Zheng Bao | eff2ffd | 2010-03-16 01:38:54 +0000 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
| 4 | * Copyright (C) 2010 Advanced Micro Devices, Inc. |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License as published by |
| 8 | * the Free Software Foundation; version 2 of the License. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
Zheng Bao | eff2ffd | 2010-03-16 01:38:54 +0000 | [diff] [blame] | 14 | */ |
| 15 | |
| 16 | #include <console/console.h> |
| 17 | #include <device/device.h> |
| 18 | #include <device/pci.h> |
| 19 | #include <device/pci_ids.h> |
| 20 | #include <device/pci_ops.h> |
Kyösti Mälkki | e2227a2 | 2014-02-05 13:02:55 +0200 | [diff] [blame] | 21 | #include <device/pci_ehci.h> |
Zheng Bao | eff2ffd | 2010-03-16 01:38:54 +0000 | [diff] [blame] | 22 | #include <arch/io.h> |
| 23 | #include "sb700.h" |
| 24 | |
| 25 | static struct pci_operations lops_pci = { |
| 26 | .set_subsystem = pci_dev_set_subsystem, |
| 27 | }; |
| 28 | |
| 29 | static void usb_init(struct device *dev) |
| 30 | { |
| 31 | u8 byte; |
| 32 | u16 word; |
Zheng Bao | c342223 | 2011-03-28 03:33:10 +0000 | [diff] [blame] | 33 | u32 dword; |
Zheng Bao | eff2ffd | 2010-03-16 01:38:54 +0000 | [diff] [blame] | 34 | |
| 35 | /* 6.1 Enable OHCI0-4 and EHCI Controllers */ |
| 36 | device_t sm_dev; |
| 37 | sm_dev = dev_find_slot(0, PCI_DEVFN(0x14, 0)); |
| 38 | byte = pci_read_config8(sm_dev, 0x68); |
| 39 | byte |= 0xFF; |
| 40 | pci_write_config8(sm_dev, 0x68, byte); |
| 41 | |
Zheng Bao | eff2ffd | 2010-03-16 01:38:54 +0000 | [diff] [blame] | 42 | /* RPR 6.2 Enables the USB PME Event,Enable USB resume support */ |
| 43 | byte = pm_ioread(0x61); |
| 44 | byte |= 1 << 6; |
| 45 | pm_iowrite(0x61, byte); |
| 46 | byte = pm_ioread(0x65); |
| 47 | byte |= 1 << 2; |
| 48 | pm_iowrite(0x65, byte); |
| 49 | |
| 50 | /* RPR 6.3 Support USB device wakeup from the S4/S5 state */ |
| 51 | byte = pm_ioread(0x65); |
| 52 | byte &= ~(1 << 0); |
| 53 | pm_iowrite(0x65, byte); |
| 54 | |
| 55 | /* RPR 6.5 Enable the USB controller to get reset by any software that generate a PCIRst# condition */ |
| 56 | byte = pm_ioread(0x65); |
| 57 | byte |= (1 << 4); |
| 58 | pm_iowrite(0x65, byte); |
| 59 | |
Zheng Bao | c342223 | 2011-03-28 03:33:10 +0000 | [diff] [blame] | 60 | /* USB_ADVANCED_SLEEP_CONTROL */ |
| 61 | byte = pm_ioread(0x95); |
| 62 | byte &= ~(7 << 0); |
| 63 | byte |= 6 << 0; /* Advanced sleep up to 6 uframes */ |
| 64 | pm_iowrite(0x95, byte); |
| 65 | |
Zheng Bao | eff2ffd | 2010-03-16 01:38:54 +0000 | [diff] [blame] | 66 | /* RPR 6.10 Disable OHCI MSI Capability. */ |
| 67 | word = pci_read_config16(dev, 0x40); |
| 68 | word |= (0x3 << 8); |
| 69 | pci_write_config16(dev, 0x40, word); |
Zheng Bao | c342223 | 2011-03-28 03:33:10 +0000 | [diff] [blame] | 70 | |
| 71 | /* USB-1_OHCI0_Corner Case S3 Wake Up */ |
| 72 | dword = pci_read_config32(dev, 0x50); |
| 73 | dword |= (1 << 16); |
| 74 | pci_write_config32(dev, 0x50, dword); |
Zheng Bao | eff2ffd | 2010-03-16 01:38:54 +0000 | [diff] [blame] | 75 | } |
| 76 | |
| 77 | static void usb_init2(struct device *dev) |
| 78 | { |
Zheng Bao | eff2ffd | 2010-03-16 01:38:54 +0000 | [diff] [blame] | 79 | u32 dword; |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 80 | void *usb2_bar0; |
Zheng Bao | eff2ffd | 2010-03-16 01:38:54 +0000 | [diff] [blame] | 81 | device_t sm_dev; |
| 82 | u8 rev; |
| 83 | |
| 84 | sm_dev = dev_find_slot(0, PCI_DEVFN(0x14, 0)); |
| 85 | rev = get_sb700_revision(sm_dev); |
| 86 | |
| 87 | /* dword = pci_read_config32(dev, 0xf8); */ |
| 88 | /* dword |= 40; */ |
| 89 | /* pci_write_config32(dev, 0xf8, dword); */ |
| 90 | |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 91 | usb2_bar0 = (void *)(pci_read_config32(dev, 0x10) & ~0xFF); |
| 92 | printk(BIOS_INFO, "usb2_bar0=0x%p\n", usb2_bar0); |
Zheng Bao | eff2ffd | 2010-03-16 01:38:54 +0000 | [diff] [blame] | 93 | |
Zheng Bao | 2a5101a | 2010-10-10 15:18:53 +0000 | [diff] [blame] | 94 | /* RPR6.4 Enables the USB PHY auto calibration resister to match 45ohm resistance */ |
Zheng Bao | eff2ffd | 2010-03-16 01:38:54 +0000 | [diff] [blame] | 95 | dword = 0x00020F00; |
| 96 | write32(usb2_bar0 + 0xC0, dword); |
| 97 | |
| 98 | /* RPR6.9 Sets In/OUT FIFO threshold for best performance */ |
| 99 | dword = 0x00400040; |
| 100 | write32(usb2_bar0 + 0xA4, dword); |
| 101 | |
| 102 | /* RPR6.11 Disabling EHCI Advance Asynchronous Enhancement */ |
| 103 | dword = pci_read_config32(dev, 0x50); |
| 104 | dword |= (1 << 28); |
| 105 | pci_write_config32(dev, 0x50, dword); |
| 106 | |
| 107 | /* RPR 6.12 EHCI Advance PHY Power Savings */ |
| 108 | /* RPR says it is just for A12. CIMM sets it when it is above A11. */ |
| 109 | /* But it makes the linux crash, so we skip it */ |
Zheng Bao | eff2ffd | 2010-03-16 01:38:54 +0000 | [diff] [blame] | 110 | dword = pci_read_config32(dev, 0x50); |
| 111 | dword |= 1 << 31; |
| 112 | pci_write_config32(dev, 0x50, dword); |
Zheng Bao | eff2ffd | 2010-03-16 01:38:54 +0000 | [diff] [blame] | 113 | |
Zheng Bao | 2a5101a | 2010-10-10 15:18:53 +0000 | [diff] [blame] | 114 | /* RPR6.13 Enabling Fix for EHCI Controller Driver Yellow Sign Issue */ |
| 115 | /* RPR says it is just for A12. CIMx sets it when it is above A11. */ |
Zheng Bao | eff2ffd | 2010-03-16 01:38:54 +0000 | [diff] [blame] | 116 | dword = pci_read_config32(dev, 0x50); |
| 117 | dword |= (1 << 20); |
| 118 | pci_write_config32(dev, 0x50, dword); |
| 119 | |
| 120 | /* RPR6.15 EHCI Async Park Mode */ |
| 121 | dword = pci_read_config32(dev, 0x50); |
| 122 | dword |= (1 << 23); |
| 123 | pci_write_config32(dev, 0x50, dword); |
| 124 | |
| 125 | /* Each step below causes the linux crashes. Leave them here |
| 126 | * for future debugging. */ |
Stefan Reinauer | 78b4033 | 2010-03-17 22:09:26 +0000 | [diff] [blame] | 127 | u8 byte; |
| 128 | u16 word; |
| 129 | |
Zheng Bao | eff2ffd | 2010-03-16 01:38:54 +0000 | [diff] [blame] | 130 | /* RPR6.16 Disable EHCI MSI support */ |
| 131 | byte = pci_read_config8(dev, 0x50); |
| 132 | byte |= (1 << 6); |
| 133 | pci_write_config8(dev, 0x50, byte); |
| 134 | |
| 135 | /* RPR6.17 Disable the EHCI Dynamic Power Saving feature */ |
| 136 | word = read32(usb2_bar0 + 0xBC); |
| 137 | word &= ~(1 << 12); |
| 138 | write16(usb2_bar0 + 0xBC, word); |
| 139 | |
| 140 | /* RPR6.19 USB Controller DMA Read Delay Tolerant. */ |
| 141 | if (rev >= REV_SB700_A14) { |
| 142 | byte = pci_read_config8(dev, 0x50); |
| 143 | byte |= (1 << 7); |
| 144 | pci_write_config8(dev, 0x50, byte); |
| 145 | } |
| 146 | |
Zheng Bao | c342223 | 2011-03-28 03:33:10 +0000 | [diff] [blame] | 147 | /* SB700_A15, USB-2_EHCI_PID_ERROR_CHECKING */ |
| 148 | if (rev == REV_SB700_A15) { |
| 149 | word = pci_read_config16(dev, 0x50); |
| 150 | word |= (1 << 9); |
| 151 | pci_write_config16(dev, 0x50, word); |
| 152 | } |
| 153 | |
Zheng Bao | eff2ffd | 2010-03-16 01:38:54 +0000 | [diff] [blame] | 154 | /* RPR6.20 Async Park Mode. */ |
| 155 | /* RPR recommends not to set these bits. */ |
| 156 | #if 0 |
| 157 | dword = pci_read_config32(dev, 0x50); |
| 158 | dword |= 1 << 23; |
| 159 | if (rev >= REV_SB700_A14) { |
| 160 | dword &= ~(1 << 2); |
| 161 | } |
| 162 | pci_write_config32(dev, 0x50, dword); |
| 163 | #endif |
| 164 | |
| 165 | /* RPR6.22 Advance Async Enhancement */ |
| 166 | /* RPR6.23 USB Periodic Cache Setting */ |
| 167 | dword = pci_read_config32(dev, 0x50); |
| 168 | if (rev == REV_SB700_A12) { |
| 169 | dword |= 1 << 28; /* 6.22 */ |
| 170 | dword |= 1 << 27; /* 6.23 */ |
| 171 | } else if (rev >= REV_SB700_A14) { |
| 172 | dword |= 1 << 3; |
| 173 | dword &= ~(1 << 28); /* 6.22 */ |
| 174 | dword |= 1 << 8; |
| 175 | dword &= ~(1 << 27); /* 6.23 */ |
| 176 | } |
efdesign98 | 00c8c4a | 2011-07-20 12:37:58 -0600 | [diff] [blame] | 177 | pci_write_config32(dev, 0x50, dword); |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 178 | printk(BIOS_DEBUG, "rpr 6.23, final dword=%x\n", dword); |
Zheng Bao | eff2ffd | 2010-03-16 01:38:54 +0000 | [diff] [blame] | 179 | } |
| 180 | |
Zheng Bao | eff2ffd | 2010-03-16 01:38:54 +0000 | [diff] [blame] | 181 | static struct device_operations usb_ops = { |
Kyösti Mälkki | fb387df | 2013-06-07 22:16:52 +0300 | [diff] [blame] | 182 | .read_resources = pci_ehci_read_resources, |
| 183 | .set_resources = pci_dev_set_resources, |
Zheng Bao | eff2ffd | 2010-03-16 01:38:54 +0000 | [diff] [blame] | 184 | .enable_resources = pci_dev_enable_resources, |
| 185 | .init = usb_init, |
| 186 | .scan_bus = 0, |
| 187 | .ops_pci = &lops_pci, |
| 188 | }; |
| 189 | |
Stefan Reinauer | 8e96ba2 | 2010-03-16 23:33:29 +0000 | [diff] [blame] | 190 | static const struct pci_driver usb_0_driver __pci_driver = { |
Zheng Bao | eff2ffd | 2010-03-16 01:38:54 +0000 | [diff] [blame] | 191 | .ops = &usb_ops, |
| 192 | .vendor = PCI_VENDOR_ID_ATI, |
| 193 | .device = PCI_DEVICE_ID_ATI_SB700_USB_18_0, |
| 194 | }; |
Zheng Bao | bfca8ef | 2010-06-19 06:55:17 +0000 | [diff] [blame] | 195 | |
Stefan Reinauer | 8e96ba2 | 2010-03-16 23:33:29 +0000 | [diff] [blame] | 196 | static const struct pci_driver usb_1_driver __pci_driver = { |
Zheng Bao | eff2ffd | 2010-03-16 01:38:54 +0000 | [diff] [blame] | 197 | .ops = &usb_ops, |
| 198 | .vendor = PCI_VENDOR_ID_ATI, |
| 199 | .device = PCI_DEVICE_ID_ATI_SB700_USB_18_1, |
| 200 | }; |
| 201 | |
| 202 | /* the pci id of usb ctrl 0 and 1 are the same. */ |
| 203 | /* |
Stefan Reinauer | 8e96ba2 | 2010-03-16 23:33:29 +0000 | [diff] [blame] | 204 | * static const struct pci_driver usb_3_driver __pci_driver = { |
Zheng Bao | eff2ffd | 2010-03-16 01:38:54 +0000 | [diff] [blame] | 205 | * .ops = &usb_ops, |
| 206 | * .vendor = PCI_VENDOR_ID_ATI, |
| 207 | * .device = PCI_DEVICE_ID_ATI_SB700_USB_19_0, |
| 208 | * }; |
Stefan Reinauer | 8e96ba2 | 2010-03-16 23:33:29 +0000 | [diff] [blame] | 209 | * static const struct pci_driver usb_4_driver __pci_driver = { |
Zheng Bao | eff2ffd | 2010-03-16 01:38:54 +0000 | [diff] [blame] | 210 | * .ops = &usb_ops, |
| 211 | * .vendor = PCI_VENDOR_ID_ATI, |
| 212 | * .device = PCI_DEVICE_ID_ATI_SB700_USB_19_1, |
| 213 | * }; |
| 214 | */ |
| 215 | |
Stefan Reinauer | 8e96ba2 | 2010-03-16 23:33:29 +0000 | [diff] [blame] | 216 | static const struct pci_driver usb_4_driver __pci_driver = { |
Zheng Bao | eff2ffd | 2010-03-16 01:38:54 +0000 | [diff] [blame] | 217 | .ops = &usb_ops, |
| 218 | .vendor = PCI_VENDOR_ID_ATI, |
| 219 | .device = PCI_DEVICE_ID_ATI_SB700_USB_20_5, |
| 220 | }; |
| 221 | |
| 222 | static struct device_operations usb_ops2 = { |
Kyösti Mälkki | fb387df | 2013-06-07 22:16:52 +0300 | [diff] [blame] | 223 | .read_resources = pci_ehci_read_resources, |
| 224 | .set_resources = pci_dev_set_resources, |
Zheng Bao | eff2ffd | 2010-03-16 01:38:54 +0000 | [diff] [blame] | 225 | .enable_resources = pci_dev_enable_resources, |
| 226 | .init = usb_init2, |
| 227 | .scan_bus = 0, |
| 228 | .ops_pci = &lops_pci, |
| 229 | }; |
| 230 | |
Stefan Reinauer | 8e96ba2 | 2010-03-16 23:33:29 +0000 | [diff] [blame] | 231 | static const struct pci_driver usb_5_driver __pci_driver = { |
Zheng Bao | eff2ffd | 2010-03-16 01:38:54 +0000 | [diff] [blame] | 232 | .ops = &usb_ops2, |
| 233 | .vendor = PCI_VENDOR_ID_ATI, |
| 234 | .device = PCI_DEVICE_ID_ATI_SB700_USB_18_2, |
| 235 | }; |
| 236 | /* |
Stefan Reinauer | 8e96ba2 | 2010-03-16 23:33:29 +0000 | [diff] [blame] | 237 | * static const struct pci_driver usb_5_driver __pci_driver = { |
Zheng Bao | eff2ffd | 2010-03-16 01:38:54 +0000 | [diff] [blame] | 238 | * .ops = &usb_ops2, |
| 239 | * .vendor = PCI_VENDOR_ID_ATI, |
| 240 | * .device = PCI_DEVICE_ID_ATI_SB700_USB_19_2, |
| 241 | * }; |
| 242 | */ |