blob: 0f092e9204e03e26c4613f0566d994512ffeb131 [file] [log] [blame]
Stefan Reinauerdebb11f2008-10-29 04:46:52 +00001/*
2 * This file is part of the coreboot project.
3 *
Stefan Reinauer54309d62009-01-20 22:53:10 +00004 * Copyright (C) 2008-2009 coresystems GmbH
Stefan Reinauerdebb11f2008-10-29 04:46:52 +00005 *
Stefan Reinauera8e11682009-03-11 14:54:18 +00006 * 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 Reinauerdebb11f2008-10-29 04:46:52 +000010 *
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
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
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"
26
27typedef struct southbridge_intel_i82801gx_config config_t;
28
29static void sata_init(struct device *dev)
30{
31 u32 reg32;
Stefan Reinauera8e11682009-03-11 14:54:18 +000032 u16 reg16;
Stefan Reinauerdebb11f2008-10-29 04:46:52 +000033 /* Get the chip configuration */
34 config_t *config = dev->chip_info;
35
36 printk_debug("i82801gx_sata: initializing...\n");
Stefan Reinauera8e11682009-03-11 14:54:18 +000037
38 if (config == NULL)
39 printk_err("i82801gx_sata: error: device not in Config.lb!\n");
40
Stefan Reinauerdebb11f2008-10-29 04:46:52 +000041 /* SATA configuration */
42
43 /* Enable BARs */
Stefan Reinauera8e11682009-03-11 14:54:18 +000044 pci_write_config16(dev, PCI_COMMAND, 0x0007);
Stefan Reinauerdebb11f2008-10-29 04:46:52 +000045
46 if (config->ide_legacy_combined) {
Stefan Reinauera8e11682009-03-11 14:54:18 +000047 printk_debug("SATA controller in combined mode.\n");
48 /* No AHCI: clear AHCI base */
49 pci_write_config32(dev, 0x24, 0x00000000);
50 /* And without AHCI BAR no memory decoding */
51 reg16 = pci_read_config16(dev, PCI_COMMAND);
52 reg16 &= ~PCI_COMMAND_MEMORY;
53 pci_write_config16(dev, PCI_COMMAND, reg16);
54
Stefan Reinauerdebb11f2008-10-29 04:46:52 +000055 pci_write_config8(dev, 0x09, 0x80);
56
57 /* Set timings */
58 pci_write_config16(dev, IDE_TIM_PRI, 0x8000);
59 pci_write_config16(dev, IDE_TIM_SEC, 0xa307);
60
61 /* Sync DMA */
62 pci_write_config16(dev, 0x48, 0x0004);
63 pci_write_config16(dev, 0x4a, 0x0200);
64
Stefan Reinauera8e11682009-03-11 14:54:18 +000065 /* Set IDE I/O Configuration */
66 reg32 = SIG_MODE_NORMAL | FAST_PCB1 | FAST_PCB0 | PCB1 | PCB0;
67 pci_write_config32(dev, IDE_CONFIG, reg32);
68
Stefan Reinauerdebb11f2008-10-29 04:46:52 +000069 /* Combine IDE - SATA configuration */
70 pci_write_config8(dev, 0x90, 0x02);
71
72 /* Port 0 & 1 enable */
73 pci_write_config8(dev, 0x92, 0x0f);
74
75 /* SATA Initialization register */
Stefan Reinauera8e11682009-03-11 14:54:18 +000076 pci_write_config32(dev, 0x94, 0x5a000180);
Stefan Reinauerdebb11f2008-10-29 04:46:52 +000077 } else if(config->sata_ahci) {
Stefan Reinauera8e11682009-03-11 14:54:18 +000078 printk_debug("SATA controller in AHCI mode.\n");
Stefan Reinauerdebb11f2008-10-29 04:46:52 +000079 /* Allow both Legacy and Native mode */
80 pci_write_config8(dev, 0x09, 0x8f);
81
82 /* Set Interrupt Line */
83 /* Interrupt Pin is set by D31IP.PIP */
84 pci_write_config8(dev, INTR_LN, 0x0a);
85
86 /* Set timings */
87 pci_write_config16(dev, IDE_TIM_PRI, 0xa307);
88 pci_write_config16(dev, IDE_TIM_SEC, 0x8000);
89
90 /* Sync DMA */
91 pci_write_config16(dev, 0x48, 0x0001);
92 pci_write_config16(dev, 0x4a, 0x0001);
93
94 /* Set IDE I/O Configuration */
95 reg32 = SIG_MODE_NORMAL | FAST_PCB1 | FAST_PCB0 | PCB1 | PCB0;
96 pci_write_config32(dev, IDE_CONFIG, reg32);
97
98 /* Set Sata Controller Mode. */
99 pci_write_config8(dev, 0x90, 0xc0); // WTF - Reserved?
100
101 /* Port 0 & 1 enable */
102 pci_write_config8(dev, 0x92, 0x0f);
103
104 /* SATA Initialization register */
105 pci_write_config32(dev, 0x94, 0x1a000180);
106 } else {
Stefan Reinauera8e11682009-03-11 14:54:18 +0000107 printk_debug("SATA controller in plain mode.\n");
108 /* Set Sata Controller Mode. No Mapping(?) */
109 pci_write_config8(dev, 0x90, 0x00);
110
111 /* No AHCI: clear AHCI base */
112 pci_write_config32(dev, 0x24, 0x00000000);
113
114 /* And without AHCI BAR no memory decoding */
115 reg16 = pci_read_config16(dev, PCI_COMMAND);
116 reg16 &= ~PCI_COMMAND_MEMORY;
117 pci_write_config16(dev, PCI_COMMAND, reg16);
118
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000119 /* Native mode capable on both primary and secondary (0xa)
120 * or'ed with enabled (0x50) = 0xf
121 */
122 pci_write_config8(dev, 0x09, 0x8f);
123
124 /* Set Interrupt Line */
125 /* Interrupt Pin is set by D31IP.PIP */
126 pci_write_config8(dev, INTR_LN, 0xff);
127
128 /* Set timings */
129 pci_write_config16(dev, IDE_TIM_PRI, 0xa307);
130 pci_write_config16(dev, IDE_TIM_SEC, 0xe303);
131
132 /* Sync DMA */
133 pci_write_config16(dev, 0x48, 0x0005);
134 pci_write_config16(dev, 0x4a, 0x0201);
135
136 /* Set IDE I/O Configuration */
137 reg32 = SIG_MODE_NORMAL | FAST_PCB1 | FAST_PCB0 | PCB1 | PCB0;
138 pci_write_config32(dev, IDE_CONFIG, reg32);
139
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000140 /* Port 0 & 1 enable XXX */
141 pci_write_config8(dev, 0x92, 0x15);
142
143 /* SATA Initialization register */
144 pci_write_config32(dev, 0x94, 0x1a000180);
145 }
146
147 /* All configurations need this SATA initialization sequence */
148 pci_write_config8(dev, 0xa0, 0x40);
149 pci_write_config8(dev, 0xa6, 0x22);
150 pci_write_config8(dev, 0xa0, 0x78);
151 pci_write_config8(dev, 0xa6, 0x22);
152 pci_write_config8(dev, 0xa0, 0x88);
153 reg32 = pci_read_config32(dev, 0xa4);
154 reg32 &= 0xc0c0c0c0;
155 reg32 |= 0x1b1b1212;
156 pci_write_config32(dev, 0xa4, reg32);
157 pci_write_config8(dev, 0xa0, 0x8c);
158 reg32 = pci_read_config32(dev, 0xa4);
159 reg32 &= 0xc0c0ff00;
160 reg32 |= 0x121200aa;
161 pci_write_config32(dev, 0xa4, reg32);
162 pci_write_config8(dev, 0xa0, 0x00);
Stefan Reinauer54309d62009-01-20 22:53:10 +0000163
164 pci_write_config8(dev, PCI_INTERRUPT_LINE, 0);
Stefan Reinauera8e11682009-03-11 14:54:18 +0000165
166 /* Sata Initialization Register */
167 reg32 = pci_read_config32(dev, 0x94);
168 reg32 |= (1 << 30); // due to some bug
169 pci_write_config32(dev, 0x94, reg32);
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000170}
171
Stefan Reinauera8e11682009-03-11 14:54:18 +0000172static void sata_set_subsystem(device_t dev, unsigned vendor, unsigned device)
173{
174 if (!vendor || !device) {
175 pci_write_config32(dev, PCI_SUBSYSTEM_VENDOR_ID,
176 pci_read_config32(dev, PCI_VENDOR_ID));
177 } else {
178 pci_write_config32(dev, PCI_SUBSYSTEM_VENDOR_ID,
179 ((device & 0xffff) << 16) | (vendor & 0xffff));
180 }
181}
182
183static struct pci_operations sata_pci_ops = {
184 .set_subsystem = sata_set_subsystem,
185};
186
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000187static struct device_operations sata_ops = {
188 .read_resources = pci_dev_read_resources,
189 .set_resources = pci_dev_set_resources,
190 .enable_resources = pci_dev_enable_resources,
191 .init = sata_init,
192 .scan_bus = 0,
193 .enable = i82801gx_enable,
Stefan Reinauera8e11682009-03-11 14:54:18 +0000194 .ops_pci = &sata_pci_ops,
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000195};
196
197/* Desktop Non-AHCI and Non-RAID Mode */
Uwe Hermannbddc6932008-10-29 13:51:31 +0000198/* 82801GB/GR/GDH (ICH7/ICH7R/ICH7DH) */
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000199static const struct pci_driver i82801gx_sata_normal_driver __pci_driver = {
200 .ops = &sata_ops,
201 .vendor = PCI_VENDOR_ID_INTEL,
Uwe Hermann5d7a1c82008-10-31 18:41:09 +0000202 .device = 0x27c0,
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000203};
204
Stefan Reinauera8e11682009-03-11 14:54:18 +0000205/* Mobile Non-AHCI and Non-RAID Mode */
206/* 82801GBM/GHM (ICH7-M/ICH7-M DH) */
207static const struct pci_driver i82801gx_sata_mobile_normal_driver __pci_driver = {
208 .ops = &sata_ops,
209 .vendor = PCI_VENDOR_ID_INTEL,
210 .device = 0x27c4,
211};
212
213
Uwe Hermannbddc6932008-10-29 13:51:31 +0000214/* NOTE: Any of the below are not properly supported yet. */
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000215
216/* Desktop AHCI Mode */
Uwe Hermannbddc6932008-10-29 13:51:31 +0000217/* 82801GB/GR/GDH (ICH7/ICH7R/ICH7DH) */
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000218static const struct pci_driver i82801gx_sata_ahci_driver __pci_driver = {
219 .ops = &sata_ops,
220 .vendor = PCI_VENDOR_ID_INTEL,
Uwe Hermann5d7a1c82008-10-31 18:41:09 +0000221 .device = 0x27c1,
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000222};
223
224/* Desktop RAID mode */
Uwe Hermannbddc6932008-10-29 13:51:31 +0000225/* 82801GB/GR/GDH (ICH7/ICH7R/ICH7DH) */
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000226static const struct pci_driver i82801gx_sata_raid_driver __pci_driver = {
227 .ops = &sata_ops,
228 .vendor = PCI_VENDOR_ID_INTEL,
Uwe Hermann5d7a1c82008-10-31 18:41:09 +0000229 .device = 0x27c3,
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000230};
231
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000232/* Mobile AHCI Mode */
Uwe Hermannbddc6932008-10-29 13:51:31 +0000233/* 82801GBM/GHM (ICH7-M/ICH7-M DH) */
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000234static const struct pci_driver i82801gx_sata_mobile_ahci_driver __pci_driver = {
235 .ops = &sata_ops,
236 .vendor = PCI_VENDOR_ID_INTEL,
Uwe Hermann5d7a1c82008-10-31 18:41:09 +0000237 .device = 0x27c5,
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000238};
239
240/* ICH7M DH Raid Mode */
Uwe Hermannbddc6932008-10-29 13:51:31 +0000241/* 82801GHM (ICH7-M DH) */
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000242static const struct pci_driver i82801gx_sata_ich7dh_raid_driver __pci_driver = {
243 .ops = &sata_ops,
244 .vendor = PCI_VENDOR_ID_INTEL,
Uwe Hermann5d7a1c82008-10-31 18:41:09 +0000245 .device = 0x27c6,
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000246};