Angel Pons | 182dbde | 2020-04-02 23:49:05 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 2 | |
| 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älkki | e2227a2 | 2014-02-05 13:02:55 +0200 | [diff] [blame] | 8 | #include <device/pci_ehci.h> |
Kyösti Mälkki | 13f6650 | 2019-03-03 08:01:05 +0200 | [diff] [blame] | 9 | #include <device/mmio.h> |
Kyösti Mälkki | f1b58b7 | 2019-03-01 13:43:02 +0200 | [diff] [blame] | 10 | #include <device/pci_ops.h> |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 11 | |
| 12 | static void usb_ehci_init(struct device *dev) |
| 13 | { |
Stefan Reinauer | a8e1168 | 2009-03-11 14:54:18 +0000 | [diff] [blame] | 14 | struct resource *res; |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 15 | u8 *base; |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 16 | u32 reg32; |
| 17 | |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 18 | printk(BIOS_DEBUG, "EHCI: Setting up controller.. "); |
Elyes HAOUAS | 1234925 | 2020-04-27 05:08:26 +0200 | [diff] [blame] | 19 | pci_or_config16(dev, PCI_COMMAND, PCI_COMMAND_MASTER | PCI_COMMAND_SERR); |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 20 | |
Angel Pons | d19332c | 2020-06-08 12:32:54 +0200 | [diff] [blame] | 21 | pci_or_config32(dev, 0xdc, (1 << 31) | (1 << 27)); |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 22 | |
Angel Pons | d19332c | 2020-06-08 12:32:54 +0200 | [diff] [blame] | 23 | pci_update_config32(dev, 0xfc, ~(3 << 2), (2 << 2) | (1 << 29) | (1 << 17)); |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 24 | |
Stefan Reinauer | a8e1168 | 2009-03-11 14:54:18 +0000 | [diff] [blame] | 25 | /* Clear any pending port changes */ |
Elyes HAOUAS | a4dd33c | 2020-08-11 09:39:43 +0200 | [diff] [blame] | 26 | res = find_resource(dev, PCI_BASE_ADDRESS_0); |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 27 | base = res2mmio(res, 0, 0); |
Stefan Reinauer | de3206a | 2010-02-22 06:09:43 +0000 | [diff] [blame] | 28 | reg32 = read32(base + 0x24) | (1 << 2); |
| 29 | write32(base + 0x24, reg32); |
Stefan Reinauer | a8e1168 | 2009-03-11 14:54:18 +0000 | [diff] [blame] | 30 | |
| 31 | /* workaround */ |
Angel Pons | d19332c | 2020-06-08 12:32:54 +0200 | [diff] [blame] | 32 | pci_or_config8(dev, 0x84, 1 << 4); |
Stefan Reinauer | a8e1168 | 2009-03-11 14:54:18 +0000 | [diff] [blame] | 33 | |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 34 | printk(BIOS_DEBUG, "done.\n"); |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 35 | } |
| 36 | |
Elyes HAOUAS | 92646ea | 2020-04-04 13:43:03 +0200 | [diff] [blame] | 37 | static void usb_ehci_set_subsystem(struct device *dev, unsigned int vendor, unsigned int device) |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 38 | { |
| 39 | u8 access_cntl; |
| 40 | |
| 41 | access_cntl = pci_read_config8(dev, 0x80); |
| 42 | |
| 43 | /* Enable writes to protected registers. */ |
| 44 | pci_write_config8(dev, 0x80, access_cntl | 1); |
| 45 | |
Subrata Banik | 4a0f071 | 2019-03-20 14:29:47 +0530 | [diff] [blame] | 46 | pci_dev_set_subsystem(dev, vendor, device); |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 47 | |
| 48 | /* Restore protection. */ |
| 49 | pci_write_config8(dev, 0x80, access_cntl); |
| 50 | } |
| 51 | |
| 52 | static struct pci_operations lops_pci = { |
| 53 | .set_subsystem = &usb_ehci_set_subsystem, |
| 54 | }; |
| 55 | |
| 56 | static struct device_operations usb_ehci_ops = { |
Kyösti Mälkki | fb387df | 2013-06-07 22:16:52 +0300 | [diff] [blame] | 57 | .read_resources = pci_ehci_read_resources, |
| 58 | .set_resources = pci_dev_set_resources, |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 59 | .enable_resources = pci_dev_enable_resources, |
| 60 | .init = usb_ehci_init, |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 61 | .enable = i82801gx_enable, |
| 62 | .ops_pci = &lops_pci, |
| 63 | }; |
| 64 | |
Uwe Hermann | bddc693 | 2008-10-29 13:51:31 +0000 | [diff] [blame] | 65 | /* 82801GB/GR/GDH/GBM/GHM/GU (ICH7/ICH7R/ICH7DH/ICH7-M/ICH7-M DH/ICH7-U) */ |
| 66 | static const struct pci_driver i82801gx_usb_ehci __pci_driver = { |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 67 | .ops = &usb_ehci_ops, |
Felix Singer | 43b7f41 | 2022-03-07 04:34:52 +0100 | [diff] [blame] | 68 | .vendor = PCI_VID_INTEL, |
Uwe Hermann | 5d7a1c8 | 2008-10-31 18:41:09 +0000 | [diff] [blame] | 69 | .device = 0x27cc, |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 70 | }; |