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. |
| 15 | * |
| 16 | * You should have received a copy of the GNU General Public License |
| 17 | * along with this program; if not, write to the Free Software |
Paul Menzel | a46a712 | 2013-02-23 18:37:27 +0100 | [diff] [blame] | 18 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 19 | */ |
| 20 | |
| 21 | #include <console/console.h> |
| 22 | #include <device/device.h> |
| 23 | #include <device/pci.h> |
| 24 | #include <device/pci_ids.h> |
| 25 | #include "i82801gx.h" |
Kyösti Mälkki | e2227a2 | 2014-02-05 13:02:55 +0200 | [diff] [blame] | 26 | #include <device/pci_ehci.h> |
Stefan Reinauer | a8e1168 | 2009-03-11 14:54:18 +0000 | [diff] [blame] | 27 | #include <arch/io.h> |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 28 | |
| 29 | static void usb_ehci_init(struct device *dev) |
| 30 | { |
Stefan Reinauer | a8e1168 | 2009-03-11 14:54:18 +0000 | [diff] [blame] | 31 | struct resource *res; |
Stefan Reinauer | 573f7d4 | 2009-07-21 21:50:34 +0000 | [diff] [blame] | 32 | u32 base; |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 33 | u32 reg32; |
Stefan Reinauer | a8e1168 | 2009-03-11 14:54:18 +0000 | [diff] [blame] | 34 | u8 reg8; |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 35 | |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 36 | printk(BIOS_DEBUG, "EHCI: Setting up controller.. "); |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 37 | reg32 = pci_read_config32(dev, PCI_COMMAND); |
Stefan Reinauer | a8e1168 | 2009-03-11 14:54:18 +0000 | [diff] [blame] | 38 | reg32 |= PCI_COMMAND_MASTER; |
| 39 | reg32 |= PCI_COMMAND_SERR; |
| 40 | pci_write_config32(dev, PCI_COMMAND, reg32); |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 41 | |
| 42 | reg32 = pci_read_config32(dev, 0xdc); |
| 43 | reg32 |= (1 << 31) | (1 << 27); |
| 44 | pci_write_config32(dev, 0xdc, reg32); |
| 45 | |
| 46 | reg32 = pci_read_config32(dev, 0xfc); |
| 47 | reg32 &= ~(3 << 2); |
| 48 | reg32 |= (2 << 2) | (1 << 29) | (1 << 17); |
| 49 | pci_write_config32(dev, 0xfc, reg32); |
| 50 | |
Stefan Reinauer | a8e1168 | 2009-03-11 14:54:18 +0000 | [diff] [blame] | 51 | /* Clear any pending port changes */ |
| 52 | res = find_resource(dev, 0x10); |
Stefan Reinauer | 573f7d4 | 2009-07-21 21:50:34 +0000 | [diff] [blame] | 53 | base = res->base; |
Stefan Reinauer | de3206a | 2010-02-22 06:09:43 +0000 | [diff] [blame] | 54 | reg32 = read32(base + 0x24) | (1 << 2); |
| 55 | write32(base + 0x24, reg32); |
Stefan Reinauer | a8e1168 | 2009-03-11 14:54:18 +0000 | [diff] [blame] | 56 | |
| 57 | /* workaround */ |
| 58 | reg8 = pci_read_config8(dev, 0x84); |
| 59 | reg8 |= (1 << 4); |
| 60 | pci_write_config8(dev, 0x84, reg8); |
| 61 | |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 62 | printk(BIOS_DEBUG, "done.\n"); |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 63 | } |
| 64 | |
Stefan Reinauer | a8e1168 | 2009-03-11 14:54:18 +0000 | [diff] [blame] | 65 | static void usb_ehci_set_subsystem(device_t dev, unsigned vendor, unsigned device) |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 66 | { |
| 67 | u8 access_cntl; |
| 68 | |
| 69 | access_cntl = pci_read_config8(dev, 0x80); |
| 70 | |
| 71 | /* Enable writes to protected registers. */ |
| 72 | pci_write_config8(dev, 0x80, access_cntl | 1); |
| 73 | |
Stefan Reinauer | a8e1168 | 2009-03-11 14:54:18 +0000 | [diff] [blame] | 74 | if (!vendor || !device) { |
| 75 | pci_write_config32(dev, PCI_SUBSYSTEM_VENDOR_ID, |
| 76 | pci_read_config32(dev, PCI_VENDOR_ID)); |
| 77 | } else { |
| 78 | pci_write_config32(dev, PCI_SUBSYSTEM_VENDOR_ID, |
| 79 | ((device & 0xffff) << 16) | (vendor & 0xffff)); |
| 80 | } |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 81 | |
| 82 | /* Restore protection. */ |
| 83 | pci_write_config8(dev, 0x80, access_cntl); |
| 84 | } |
| 85 | |
| 86 | static struct pci_operations lops_pci = { |
| 87 | .set_subsystem = &usb_ehci_set_subsystem, |
| 88 | }; |
| 89 | |
| 90 | static struct device_operations usb_ehci_ops = { |
Kyösti Mälkki | fb387df | 2013-06-07 22:16:52 +0300 | [diff] [blame] | 91 | .read_resources = pci_ehci_read_resources, |
| 92 | .set_resources = pci_dev_set_resources, |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 93 | .enable_resources = pci_dev_enable_resources, |
| 94 | .init = usb_ehci_init, |
| 95 | .scan_bus = 0, |
| 96 | .enable = i82801gx_enable, |
| 97 | .ops_pci = &lops_pci, |
| 98 | }; |
| 99 | |
Uwe Hermann | bddc693 | 2008-10-29 13:51:31 +0000 | [diff] [blame] | 100 | /* 82801GB/GR/GDH/GBM/GHM/GU (ICH7/ICH7R/ICH7DH/ICH7-M/ICH7-M DH/ICH7-U) */ |
| 101 | static const struct pci_driver i82801gx_usb_ehci __pci_driver = { |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 102 | .ops = &usb_ehci_ops, |
| 103 | .vendor = PCI_VENDOR_ID_INTEL, |
Uwe Hermann | 5d7a1c8 | 2008-10-31 18:41:09 +0000 | [diff] [blame] | 104 | .device = 0x27cc, |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 105 | }; |