arch import user (historical) | 98d0d30 | 2005-07-06 17:13:46 +0000 | [diff] [blame] | 1 | /* |
Uwe Hermann | 8af6d55 | 2010-10-17 19:13:18 +0000 | [diff] [blame] | 2 | * This file is part of the coreboot project. |
| 3 | * |
| 4 | * Copyright (C) 2004 Tyan Computer |
| 5 | * Written by Yinghai Lu <yhlu@tyan.com> for Tyan Computer. |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify |
| 8 | * it under the terms of the GNU General Public License as published by |
| 9 | * the Free Software Foundation; version 2 of the License. |
| 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. |
arch import user (historical) | 98d0d30 | 2005-07-06 17:13:46 +0000 | [diff] [blame] | 15 | */ |
Uwe Hermann | 7f3d48c | 2008-10-02 18:19:17 +0000 | [diff] [blame] | 16 | |
arch import user (historical) | 98d0d30 | 2005-07-06 17:13:46 +0000 | [diff] [blame] | 17 | #include <console/console.h> |
| 18 | #include <device/device.h> |
| 19 | #include <delay.h> |
| 20 | #include <device/pci.h> |
| 21 | #include <device/pci_ids.h> |
| 22 | #include <device/pci_ops.h> |
Kyösti Mälkki | 413e3da | 2015-02-03 08:05:55 +0200 | [diff] [blame] | 23 | #include "chip.h" |
arch import user (historical) | 98d0d30 | 2005-07-06 17:13:46 +0000 | [diff] [blame] | 24 | |
Myles Watson | fa12b67 | 2009-04-30 22:45:41 +0000 | [diff] [blame] | 25 | #ifndef CK804_SATA_RESET_FOR_ATAPI |
| 26 | #define CK804_SATA_RESET_FOR_ATAPI 0 |
| 27 | #endif |
| 28 | |
Myles Watson | c4ddbff | 2009-02-09 17:52:54 +0000 | [diff] [blame] | 29 | #if CK804_SATA_RESET_FOR_ATAPI |
arch import user (historical) | 98d0d30 | 2005-07-06 17:13:46 +0000 | [diff] [blame] | 30 | static void sata_com_reset(struct device *dev, unsigned reset) |
| 31 | // reset = 1 : reset |
| 32 | // reset = 0 : clear |
| 33 | { |
Uwe Hermann | 7e2fbd5 | 2011-01-04 17:36:55 +0000 | [diff] [blame] | 34 | u32 *base; |
| 35 | u32 dword; |
arch import user (historical) | 98d0d30 | 2005-07-06 17:13:46 +0000 | [diff] [blame] | 36 | int loop; |
| 37 | |
Uwe Hermann | 7e2fbd5 | 2011-01-04 17:36:55 +0000 | [diff] [blame] | 38 | base = (u32 *) pci_read_config32(dev, 0x24); |
arch import user (historical) | 98d0d30 | 2005-07-06 17:13:46 +0000 | [diff] [blame] | 39 | |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 40 | printk(BIOS_DEBUG, "base = %08lx\n", base); |
arch import user (historical) | 98d0d30 | 2005-07-06 17:13:46 +0000 | [diff] [blame] | 41 | |
Uwe Hermann | 7f3d48c | 2008-10-02 18:19:17 +0000 | [diff] [blame] | 42 | if (reset) { |
| 43 | *(base + 4) = 0xffffffff; |
| 44 | *(base + 0x44) = 0xffffffff; |
Myles Watson | 64caf36 | 2008-09-18 16:27:00 +0000 | [diff] [blame] | 45 | } |
arch import user (historical) | 98d0d30 | 2005-07-06 17:13:46 +0000 | [diff] [blame] | 46 | |
Uwe Hermann | 7f3d48c | 2008-10-02 18:19:17 +0000 | [diff] [blame] | 47 | dword = *(base + 8); |
Myles Watson | 64caf36 | 2008-09-18 16:27:00 +0000 | [diff] [blame] | 48 | dword &= ~(0xf); |
| 49 | dword |= reset; |
arch import user (historical) | 98d0d30 | 2005-07-06 17:13:46 +0000 | [diff] [blame] | 50 | |
Myles Watson | 64caf36 | 2008-09-18 16:27:00 +0000 | [diff] [blame] | 51 | *(base + 8) = dword; |
| 52 | *(base + 0x48) = dword; |
arch import user (historical) | 98d0d30 | 2005-07-06 17:13:46 +0000 | [diff] [blame] | 53 | |
| 54 | #if 0 |
| 55 | udelay(1000); |
| 56 | dword &= ~(0xf); |
Myles Watson | 64caf36 | 2008-09-18 16:27:00 +0000 | [diff] [blame] | 57 | *(base + 8) = dword; |
| 58 | *(base + 0x48) = dword; |
arch import user (historical) | 98d0d30 | 2005-07-06 17:13:46 +0000 | [diff] [blame] | 59 | #endif |
arch import user (historical) | 98d0d30 | 2005-07-06 17:13:46 +0000 | [diff] [blame] | 60 | |
Uwe Hermann | 7f3d48c | 2008-10-02 18:19:17 +0000 | [diff] [blame] | 61 | if (reset) |
| 62 | return; |
arch import user (historical) | 98d0d30 | 2005-07-06 17:13:46 +0000 | [diff] [blame] | 63 | |
Uwe Hermann | 7f3d48c | 2008-10-02 18:19:17 +0000 | [diff] [blame] | 64 | dword = *(base + 0); |
Stefan Reinauer | 64ed2b7 | 2010-03-31 14:47:43 +0000 | [diff] [blame] | 65 | printk(BIOS_DEBUG, "*(base+0)=%08x\n", dword); |
Uwe Hermann | 7f3d48c | 2008-10-02 18:19:17 +0000 | [diff] [blame] | 66 | if (dword == 0x113) { |
| 67 | loop = 200000; // 2 |
arch import user (historical) | 98d0d30 | 2005-07-06 17:13:46 +0000 | [diff] [blame] | 68 | do { |
Uwe Hermann | 7f3d48c | 2008-10-02 18:19:17 +0000 | [diff] [blame] | 69 | dword = *(base + 4); |
| 70 | if ((dword & 0x10000) != 0) |
| 71 | break; |
arch import user (historical) | 98d0d30 | 2005-07-06 17:13:46 +0000 | [diff] [blame] | 72 | udelay(10); |
Uwe Hermann | 7f3d48c | 2008-10-02 18:19:17 +0000 | [diff] [blame] | 73 | } while (--loop > 0); |
Stefan Reinauer | 64ed2b7 | 2010-03-31 14:47:43 +0000 | [diff] [blame] | 74 | printk(BIOS_DEBUG, "loop=%d, *(base+4)=%08x\n", loop, dword); |
arch import user (historical) | 98d0d30 | 2005-07-06 17:13:46 +0000 | [diff] [blame] | 75 | } |
arch import user (historical) | 98d0d30 | 2005-07-06 17:13:46 +0000 | [diff] [blame] | 76 | |
Uwe Hermann | 7f3d48c | 2008-10-02 18:19:17 +0000 | [diff] [blame] | 77 | dword = *(base + 0x40); |
Stefan Reinauer | 64ed2b7 | 2010-03-31 14:47:43 +0000 | [diff] [blame] | 78 | printk(BIOS_DEBUG, "*(base+0x40)=%08x\n", dword); |
Uwe Hermann | 7f3d48c | 2008-10-02 18:19:17 +0000 | [diff] [blame] | 79 | if (dword == 0x113) { |
| 80 | loop = 200000; //2 |
| 81 | do { |
| 82 | dword = *(base + 0x44); |
| 83 | if ((dword & 0x10000) != 0) |
| 84 | break; |
arch import user (historical) | 98d0d30 | 2005-07-06 17:13:46 +0000 | [diff] [blame] | 85 | udelay(10); |
Uwe Hermann | 7f3d48c | 2008-10-02 18:19:17 +0000 | [diff] [blame] | 86 | } while (--loop > 0); |
Stefan Reinauer | 64ed2b7 | 2010-03-31 14:47:43 +0000 | [diff] [blame] | 87 | printk(BIOS_DEBUG, "loop=%d, *(base+0x44)=%08x\n", loop, dword); |
arch import user (historical) | 98d0d30 | 2005-07-06 17:13:46 +0000 | [diff] [blame] | 88 | } |
arch import user (historical) | 98d0d30 | 2005-07-06 17:13:46 +0000 | [diff] [blame] | 89 | } |
Myles Watson | c4ddbff | 2009-02-09 17:52:54 +0000 | [diff] [blame] | 90 | #endif |
arch import user (historical) | 98d0d30 | 2005-07-06 17:13:46 +0000 | [diff] [blame] | 91 | |
| 92 | static void sata_init(struct device *dev) |
| 93 | { |
Uwe Hermann | 7e2fbd5 | 2011-01-04 17:36:55 +0000 | [diff] [blame] | 94 | u32 dword; |
arch import user (historical) | 98d0d30 | 2005-07-06 17:13:46 +0000 | [diff] [blame] | 95 | struct southbridge_nvidia_ck804_config *conf; |
Uwe Hermann | 7f3d48c | 2008-10-02 18:19:17 +0000 | [diff] [blame] | 96 | |
arch import user (historical) | 98d0d30 | 2005-07-06 17:13:46 +0000 | [diff] [blame] | 97 | conf = dev->chip_info; |
| 98 | |
Myles Watson | 64caf36 | 2008-09-18 16:27:00 +0000 | [diff] [blame] | 99 | dword = pci_read_config32(dev, 0x50); |
Uwe Hermann | 7f3d48c | 2008-10-02 18:19:17 +0000 | [diff] [blame] | 100 | /* Ensure prefetch is disabled. */ |
Myles Watson | 64caf36 | 2008-09-18 16:27:00 +0000 | [diff] [blame] | 101 | dword &= ~((1 << 15) | (1 << 13)); |
| 102 | if (conf->sata1_enable) { |
Uwe Hermann | 7f3d48c | 2008-10-02 18:19:17 +0000 | [diff] [blame] | 103 | /* Enable secondary SATA interface. */ |
| 104 | dword |= (1 << 0); |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 105 | printk(BIOS_DEBUG, "SATA S \t"); |
Myles Watson | 64caf36 | 2008-09-18 16:27:00 +0000 | [diff] [blame] | 106 | } |
| 107 | if (conf->sata0_enable) { |
Uwe Hermann | 7f3d48c | 2008-10-02 18:19:17 +0000 | [diff] [blame] | 108 | /* Enable primary SATA interface. */ |
| 109 | dword |= (1 << 1); |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 110 | printk(BIOS_DEBUG, "SATA P \n"); |
Myles Watson | 64caf36 | 2008-09-18 16:27:00 +0000 | [diff] [blame] | 111 | } |
Yinghai Lu | 5dab7d6 | 2005-10-01 07:32:04 +0000 | [diff] [blame] | 112 | #if 0 |
Uwe Hermann | 7f3d48c | 2008-10-02 18:19:17 +0000 | [diff] [blame] | 113 | /* Write back */ |
| 114 | dword |= (1 << 12); |
| 115 | dword |= (1 << 14); |
Yinghai Lu | 5dab7d6 | 2005-10-01 07:32:04 +0000 | [diff] [blame] | 116 | #endif |
arch import user (historical) | 98d0d30 | 2005-07-06 17:13:46 +0000 | [diff] [blame] | 117 | |
Yinghai Lu | 5dab7d6 | 2005-10-01 07:32:04 +0000 | [diff] [blame] | 118 | #if 0 |
Uwe Hermann | 7f3d48c | 2008-10-02 18:19:17 +0000 | [diff] [blame] | 119 | /* ADMA */ |
| 120 | dword |= (1 << 16); |
| 121 | dword |= (1 << 17); |
arch import user (historical) | 98d0d30 | 2005-07-06 17:13:46 +0000 | [diff] [blame] | 122 | #endif |
| 123 | |
Myles Watson | 64caf36 | 2008-09-18 16:27:00 +0000 | [diff] [blame] | 124 | #if 1 |
Uwe Hermann | 7f3d48c | 2008-10-02 18:19:17 +0000 | [diff] [blame] | 125 | /* DO NOT relay OK and PAGE_FRNDLY_DTXFR_CNT. */ |
| 126 | dword &= ~(0x1f << 24); |
| 127 | dword |= (0x15 << 24); |
arch import user (historical) | 98d0d30 | 2005-07-06 17:13:46 +0000 | [diff] [blame] | 128 | #endif |
Myles Watson | 64caf36 | 2008-09-18 16:27:00 +0000 | [diff] [blame] | 129 | pci_write_config32(dev, 0x50, dword); |
arch import user (historical) | 98d0d30 | 2005-07-06 17:13:46 +0000 | [diff] [blame] | 130 | |
Yinghai Lu | 5dab7d6 | 2005-10-01 07:32:04 +0000 | [diff] [blame] | 131 | #if 0 |
Uwe Hermann | 7f3d48c | 2008-10-02 18:19:17 +0000 | [diff] [blame] | 132 | /* SLUMBER_DURING_D3 */ |
Myles Watson | 64caf36 | 2008-09-18 16:27:00 +0000 | [diff] [blame] | 133 | dword = pci_read_config32(dev, 0x7c); |
Uwe Hermann | 7f3d48c | 2008-10-02 18:19:17 +0000 | [diff] [blame] | 134 | dword &= ~(1 << 4); |
Myles Watson | 64caf36 | 2008-09-18 16:27:00 +0000 | [diff] [blame] | 135 | pci_write_config32(dev, 0x7c, dword); |
arch import user (historical) | 98d0d30 | 2005-07-06 17:13:46 +0000 | [diff] [blame] | 136 | |
| 137 | dword = pci_read_config32(dev, 0xd0); |
Uwe Hermann | 7f3d48c | 2008-10-02 18:19:17 +0000 | [diff] [blame] | 138 | dword &= ~(0xff << 24); |
| 139 | dword |= (0x68 << 24); |
arch import user (historical) | 98d0d30 | 2005-07-06 17:13:46 +0000 | [diff] [blame] | 140 | pci_write_config32(dev, 0xd0, dword); |
| 141 | |
Myles Watson | 64caf36 | 2008-09-18 16:27:00 +0000 | [diff] [blame] | 142 | dword = pci_read_config32(dev, 0xe0); |
Uwe Hermann | 7f3d48c | 2008-10-02 18:19:17 +0000 | [diff] [blame] | 143 | dword &= ~(0xff << 24); |
| 144 | dword |= (0x68 << 24); |
arch import user (historical) | 98d0d30 | 2005-07-06 17:13:46 +0000 | [diff] [blame] | 145 | pci_write_config32(dev, 0xe0, dword); |
| 146 | #endif |
| 147 | |
Myles Watson | 64caf36 | 2008-09-18 16:27:00 +0000 | [diff] [blame] | 148 | dword = pci_read_config32(dev, 0xf8); |
| 149 | dword |= 2; |
| 150 | pci_write_config32(dev, 0xf8, dword); |
arch import user (historical) | 98d0d30 | 2005-07-06 17:13:46 +0000 | [diff] [blame] | 151 | |
Myles Watson | c4ddbff | 2009-02-09 17:52:54 +0000 | [diff] [blame] | 152 | #if CK804_SATA_RESET_FOR_ATAPI |
arch import user (historical) | 98d0d30 | 2005-07-06 17:13:46 +0000 | [diff] [blame] | 153 | dword = pci_read_config32(dev, 0xac); |
Uwe Hermann | 7f3d48c | 2008-10-02 18:19:17 +0000 | [diff] [blame] | 154 | dword &= ~((1 << 13) | (1 << 14)); |
| 155 | dword |= (1 << 13) | (0 << 14); |
arch import user (historical) | 98d0d30 | 2005-07-06 17:13:46 +0000 | [diff] [blame] | 156 | pci_write_config32(dev, 0xac, dword); |
| 157 | |
Uwe Hermann | 7f3d48c | 2008-10-02 18:19:17 +0000 | [diff] [blame] | 158 | sata_com_reset(dev, 1); /* For discover some s-atapi device. */ |
arch import user (historical) | 98d0d30 | 2005-07-06 17:13:46 +0000 | [diff] [blame] | 159 | #endif |
arch import user (historical) | 98d0d30 | 2005-07-06 17:13:46 +0000 | [diff] [blame] | 160 | } |
| 161 | |
Uwe Hermann | 7f3d48c | 2008-10-02 18:19:17 +0000 | [diff] [blame] | 162 | static struct device_operations sata_ops = { |
arch import user (historical) | 98d0d30 | 2005-07-06 17:13:46 +0000 | [diff] [blame] | 163 | .read_resources = pci_dev_read_resources, |
| 164 | .set_resources = pci_dev_set_resources, |
| 165 | .enable_resources = pci_dev_enable_resources, |
arch import user (historical) | 98d0d30 | 2005-07-06 17:13:46 +0000 | [diff] [blame] | 166 | .init = sata_init, |
| 167 | .scan_bus = 0, |
Jonathan Kollasch | c7f3f80 | 2010-10-29 15:56:04 +0000 | [diff] [blame] | 168 | .ops_pci = &ck804_pci_ops, |
arch import user (historical) | 98d0d30 | 2005-07-06 17:13:46 +0000 | [diff] [blame] | 169 | }; |
| 170 | |
Stefan Reinauer | f1cf1f7 | 2007-10-24 09:08:58 +0000 | [diff] [blame] | 171 | static const struct pci_driver sata0_driver __pci_driver = { |
arch import user (historical) | 98d0d30 | 2005-07-06 17:13:46 +0000 | [diff] [blame] | 172 | .ops = &sata_ops, |
| 173 | .vendor = PCI_VENDOR_ID_NVIDIA, |
| 174 | .device = PCI_DEVICE_ID_NVIDIA_CK804_SATA0, |
| 175 | }; |
| 176 | |
Stefan Reinauer | f1cf1f7 | 2007-10-24 09:08:58 +0000 | [diff] [blame] | 177 | static const struct pci_driver sata1_driver __pci_driver = { |
Myles Watson | 64caf36 | 2008-09-18 16:27:00 +0000 | [diff] [blame] | 178 | .ops = &sata_ops, |
| 179 | .vendor = PCI_VENDOR_ID_NVIDIA, |
| 180 | .device = PCI_DEVICE_ID_NVIDIA_CK804_SATA1, |
arch import user (historical) | 98d0d30 | 2005-07-06 17:13:46 +0000 | [diff] [blame] | 181 | }; |