Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
Stefan Reinauer | a8e1168 | 2009-03-11 14:54:18 +0000 | [diff] [blame] | 4 | * Copyright (C) 2008-2009 coresystems GmbH |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 5 | * |
Stefan Reinauer | a8e1168 | 2009-03-11 14:54:18 +0000 | [diff] [blame] | 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. |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 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 Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 15 | */ |
| 16 | |
| 17 | #include <console/console.h> |
| 18 | #include <device/device.h> |
| 19 | #include <device/pci.h> |
| 20 | #include <device/pci_ids.h> |
| 21 | #include "i82801gx.h" |
Kyösti Mälkki | e2227a2 | 2014-02-05 13:02:55 +0200 | [diff] [blame] | 22 | #include <device/pci_ehci.h> |
Kyösti Mälkki | 13f6650 | 2019-03-03 08:01:05 +0200 | [diff] [blame] | 23 | #include <device/mmio.h> |
Kyösti Mälkki | f1b58b7 | 2019-03-01 13:43:02 +0200 | [diff] [blame] | 24 | #include <device/pci_ops.h> |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 25 | |
| 26 | static void usb_ehci_init(struct device *dev) |
| 27 | { |
Stefan Reinauer | a8e1168 | 2009-03-11 14:54:18 +0000 | [diff] [blame] | 28 | struct resource *res; |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 29 | u8 *base; |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 30 | u32 reg32; |
Stefan Reinauer | a8e1168 | 2009-03-11 14:54:18 +0000 | [diff] [blame] | 31 | u8 reg8; |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 32 | |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 33 | printk(BIOS_DEBUG, "EHCI: Setting up controller.. "); |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 34 | reg32 = pci_read_config32(dev, PCI_COMMAND); |
Stefan Reinauer | a8e1168 | 2009-03-11 14:54:18 +0000 | [diff] [blame] | 35 | reg32 |= PCI_COMMAND_MASTER; |
| 36 | reg32 |= PCI_COMMAND_SERR; |
| 37 | pci_write_config32(dev, PCI_COMMAND, reg32); |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 38 | |
| 39 | reg32 = pci_read_config32(dev, 0xdc); |
| 40 | reg32 |= (1 << 31) | (1 << 27); |
| 41 | pci_write_config32(dev, 0xdc, reg32); |
| 42 | |
| 43 | reg32 = pci_read_config32(dev, 0xfc); |
| 44 | reg32 &= ~(3 << 2); |
| 45 | reg32 |= (2 << 2) | (1 << 29) | (1 << 17); |
| 46 | pci_write_config32(dev, 0xfc, reg32); |
| 47 | |
Stefan Reinauer | a8e1168 | 2009-03-11 14:54:18 +0000 | [diff] [blame] | 48 | /* Clear any pending port changes */ |
| 49 | res = find_resource(dev, 0x10); |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 50 | base = res2mmio(res, 0, 0); |
Stefan Reinauer | de3206a | 2010-02-22 06:09:43 +0000 | [diff] [blame] | 51 | reg32 = read32(base + 0x24) | (1 << 2); |
| 52 | write32(base + 0x24, reg32); |
Stefan Reinauer | a8e1168 | 2009-03-11 14:54:18 +0000 | [diff] [blame] | 53 | |
| 54 | /* workaround */ |
| 55 | reg8 = pci_read_config8(dev, 0x84); |
| 56 | reg8 |= (1 << 4); |
| 57 | pci_write_config8(dev, 0x84, reg8); |
| 58 | |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 59 | printk(BIOS_DEBUG, "done.\n"); |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 60 | } |
| 61 | |
Elyes HAOUAS | 9966703 | 2018-05-13 12:47:28 +0200 | [diff] [blame] | 62 | static void usb_ehci_set_subsystem(struct device *dev, unsigned int vendor, |
| 63 | unsigned int device) |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 64 | { |
| 65 | u8 access_cntl; |
| 66 | |
| 67 | access_cntl = pci_read_config8(dev, 0x80); |
| 68 | |
| 69 | /* Enable writes to protected registers. */ |
| 70 | pci_write_config8(dev, 0x80, access_cntl | 1); |
| 71 | |
Subrata Banik | 4a0f071 | 2019-03-20 14:29:47 +0530 | [diff] [blame^] | 72 | pci_dev_set_subsystem(dev, vendor, device); |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 73 | |
| 74 | /* Restore protection. */ |
| 75 | pci_write_config8(dev, 0x80, access_cntl); |
| 76 | } |
| 77 | |
| 78 | static struct pci_operations lops_pci = { |
| 79 | .set_subsystem = &usb_ehci_set_subsystem, |
| 80 | }; |
| 81 | |
| 82 | static struct device_operations usb_ehci_ops = { |
Kyösti Mälkki | fb387df | 2013-06-07 22:16:52 +0300 | [diff] [blame] | 83 | .read_resources = pci_ehci_read_resources, |
| 84 | .set_resources = pci_dev_set_resources, |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 85 | .enable_resources = pci_dev_enable_resources, |
| 86 | .init = usb_ehci_init, |
| 87 | .scan_bus = 0, |
| 88 | .enable = i82801gx_enable, |
| 89 | .ops_pci = &lops_pci, |
| 90 | }; |
| 91 | |
Uwe Hermann | bddc693 | 2008-10-29 13:51:31 +0000 | [diff] [blame] | 92 | /* 82801GB/GR/GDH/GBM/GHM/GU (ICH7/ICH7R/ICH7DH/ICH7-M/ICH7-M DH/ICH7-U) */ |
| 93 | static const struct pci_driver i82801gx_usb_ehci __pci_driver = { |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 94 | .ops = &usb_ehci_ops, |
| 95 | .vendor = PCI_VENDOR_ID_INTEL, |
Uwe Hermann | 5d7a1c8 | 2008-10-31 18:41:09 +0000 | [diff] [blame] | 96 | .device = 0x27cc, |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 97 | }; |