blob: 811dc503b72b6455afb5cccd4d55199fbc3a523d [file] [log] [blame]
Angel Pons182dbde2020-04-02 23:49:05 +02001/* SPDX-License-Identifier: GPL-2.0-only */
Stefan Reinauerdebb11f2008-10-29 04:46:52 +00002
3#include <console/console.h>
4#include <device/device.h>
5#include <device/pci.h>
6#include <device/pci_ids.h>
7#include "i82801gx.h"
Kyösti Mälkkie2227a22014-02-05 13:02:55 +02008#include <device/pci_ehci.h>
Kyösti Mälkki13f66502019-03-03 08:01:05 +02009#include <device/mmio.h>
Elyes HAOUASa4dd33c2020-08-11 09:39:43 +020010#include <device/pci_def.h>
Kyösti Mälkkif1b58b72019-03-01 13:43:02 +020011#include <device/pci_ops.h>
Stefan Reinauerdebb11f2008-10-29 04:46:52 +000012
13static void usb_ehci_init(struct device *dev)
14{
Stefan Reinauera8e11682009-03-11 14:54:18 +000015 struct resource *res;
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -080016 u8 *base;
Stefan Reinauerdebb11f2008-10-29 04:46:52 +000017 u32 reg32;
18
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +000019 printk(BIOS_DEBUG, "EHCI: Setting up controller.. ");
Elyes HAOUAS12349252020-04-27 05:08:26 +020020 pci_or_config16(dev, PCI_COMMAND, PCI_COMMAND_MASTER | PCI_COMMAND_SERR);
Stefan Reinauerdebb11f2008-10-29 04:46:52 +000021
Angel Ponsd19332c2020-06-08 12:32:54 +020022 pci_or_config32(dev, 0xdc, (1 << 31) | (1 << 27));
Stefan Reinauerdebb11f2008-10-29 04:46:52 +000023
Angel Ponsd19332c2020-06-08 12:32:54 +020024 pci_update_config32(dev, 0xfc, ~(3 << 2), (2 << 2) | (1 << 29) | (1 << 17));
Stefan Reinauerdebb11f2008-10-29 04:46:52 +000025
Stefan Reinauera8e11682009-03-11 14:54:18 +000026 /* Clear any pending port changes */
Elyes HAOUASa4dd33c2020-08-11 09:39:43 +020027 res = find_resource(dev, PCI_BASE_ADDRESS_0);
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -080028 base = res2mmio(res, 0, 0);
Stefan Reinauerde3206a2010-02-22 06:09:43 +000029 reg32 = read32(base + 0x24) | (1 << 2);
30 write32(base + 0x24, reg32);
Stefan Reinauera8e11682009-03-11 14:54:18 +000031
32 /* workaround */
Angel Ponsd19332c2020-06-08 12:32:54 +020033 pci_or_config8(dev, 0x84, 1 << 4);
Stefan Reinauera8e11682009-03-11 14:54:18 +000034
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +000035 printk(BIOS_DEBUG, "done.\n");
Stefan Reinauerdebb11f2008-10-29 04:46:52 +000036}
37
Elyes HAOUAS92646ea2020-04-04 13:43:03 +020038static void usb_ehci_set_subsystem(struct device *dev, unsigned int vendor, unsigned int device)
Stefan Reinauerdebb11f2008-10-29 04:46:52 +000039{
40 u8 access_cntl;
41
42 access_cntl = pci_read_config8(dev, 0x80);
43
44 /* Enable writes to protected registers. */
45 pci_write_config8(dev, 0x80, access_cntl | 1);
46
Subrata Banik4a0f0712019-03-20 14:29:47 +053047 pci_dev_set_subsystem(dev, vendor, device);
Stefan Reinauerdebb11f2008-10-29 04:46:52 +000048
49 /* Restore protection. */
50 pci_write_config8(dev, 0x80, access_cntl);
51}
52
53static struct pci_operations lops_pci = {
54 .set_subsystem = &usb_ehci_set_subsystem,
55};
56
57static struct device_operations usb_ehci_ops = {
Kyösti Mälkkifb387df2013-06-07 22:16:52 +030058 .read_resources = pci_ehci_read_resources,
59 .set_resources = pci_dev_set_resources,
Stefan Reinauerdebb11f2008-10-29 04:46:52 +000060 .enable_resources = pci_dev_enable_resources,
61 .init = usb_ehci_init,
Stefan Reinauerdebb11f2008-10-29 04:46:52 +000062 .enable = i82801gx_enable,
63 .ops_pci = &lops_pci,
64};
65
Uwe Hermannbddc6932008-10-29 13:51:31 +000066/* 82801GB/GR/GDH/GBM/GHM/GU (ICH7/ICH7R/ICH7DH/ICH7-M/ICH7-M DH/ICH7-U) */
67static const struct pci_driver i82801gx_usb_ehci __pci_driver = {
Stefan Reinauerdebb11f2008-10-29 04:46:52 +000068 .ops = &usb_ehci_ops,
Felix Singer43b7f412022-03-07 04:34:52 +010069 .vendor = PCI_VID_INTEL,
Uwe Hermann5d7a1c82008-10-31 18:41:09 +000070 .device = 0x27cc,
Stefan Reinauerdebb11f2008-10-29 04:46:52 +000071};