2 * This file is part of the coreboot project.
4 * Copyright (C) 2008-2009 coresystems GmbH
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
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.
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
21 #include <console/console.h>
22 #include <device/device.h>
23 #include <device/pci.h>
24 #include <device/pci_ids.h>
27 typedef struct southbridge_intel_i82801gx_config config_t;
29 static void sata_init(struct device *dev)
33 /* Get the chip configuration */
34 config_t *config = dev->chip_info;
36 printk_debug("i82801gx_sata: initializing...\n");
39 printk_err("i82801gx_sata: error: device not in Config.lb!\n");
41 /* SATA configuration */
44 pci_write_config16(dev, PCI_COMMAND, 0x0007);
46 if (config->ide_legacy_combined) {
47 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);
55 pci_write_config8(dev, 0x09, 0x80);
58 pci_write_config16(dev, IDE_TIM_PRI, 0x8000);
59 pci_write_config16(dev, IDE_TIM_SEC, 0xa307);
62 pci_write_config16(dev, 0x48, 0x0004);
63 pci_write_config16(dev, 0x4a, 0x0200);
65 /* Set IDE I/O Configuration */
66 reg32 = SIG_MODE_NORMAL | FAST_PCB1 | FAST_PCB0 | PCB1 | PCB0;
67 pci_write_config32(dev, IDE_CONFIG, reg32);
69 /* Combine IDE - SATA configuration */
70 pci_write_config8(dev, 0x90, 0x02);
72 /* Port 0 & 1 enable */
73 pci_write_config8(dev, 0x92, 0x0f);
75 /* SATA Initialization register */
76 pci_write_config32(dev, 0x94, 0x5a000180);
77 } else if(config->sata_ahci) {
78 printk_debug("SATA controller in AHCI mode.\n");
79 /* Allow both Legacy and Native mode */
80 pci_write_config8(dev, 0x09, 0x8f);
82 /* Set Interrupt Line */
83 /* Interrupt Pin is set by D31IP.PIP */
84 pci_write_config8(dev, INTR_LN, 0x0a);
87 pci_write_config16(dev, IDE_TIM_PRI, 0xa307);
88 pci_write_config16(dev, IDE_TIM_SEC, 0x8000);
91 pci_write_config16(dev, 0x48, 0x0001);
92 pci_write_config16(dev, 0x4a, 0x0001);
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);
98 /* Set Sata Controller Mode. */
99 pci_write_config8(dev, 0x90, 0xc0); // WTF - Reserved?
101 /* Port 0 & 1 enable */
102 pci_write_config8(dev, 0x92, 0x0f);
104 /* SATA Initialization register */
105 pci_write_config32(dev, 0x94, 0x1a000180);
107 printk_debug("SATA controller in plain mode.\n");
108 /* Set Sata Controller Mode. No Mapping(?) */
109 pci_write_config8(dev, 0x90, 0x00);
111 /* No AHCI: clear AHCI base */
112 pci_write_config32(dev, 0x24, 0x00000000);
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);
119 /* Native mode capable on both primary and secondary (0xa)
120 * or'ed with enabled (0x50) = 0xf
122 pci_write_config8(dev, 0x09, 0x8f);
124 /* Set Interrupt Line */
125 /* Interrupt Pin is set by D31IP.PIP */
126 pci_write_config8(dev, INTR_LN, 0xff);
129 pci_write_config16(dev, IDE_TIM_PRI, 0xa307);
130 pci_write_config16(dev, IDE_TIM_SEC, 0xe303);
133 pci_write_config16(dev, 0x48, 0x0005);
134 pci_write_config16(dev, 0x4a, 0x0201);
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);
140 /* Port 0 & 1 enable XXX */
141 pci_write_config8(dev, 0x92, 0x15);
143 /* SATA Initialization register */
144 pci_write_config32(dev, 0x94, 0x1a000180);
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);
156 pci_write_config32(dev, 0xa4, reg32);
157 pci_write_config8(dev, 0xa0, 0x8c);
158 reg32 = pci_read_config32(dev, 0xa4);
161 pci_write_config32(dev, 0xa4, reg32);
162 pci_write_config8(dev, 0xa0, 0x00);
164 pci_write_config8(dev, PCI_INTERRUPT_LINE, 0);
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);
172 static void sata_set_subsystem(device_t dev, unsigned vendor, unsigned device)
174 if (!vendor || !device) {
175 pci_write_config32(dev, PCI_SUBSYSTEM_VENDOR_ID,
176 pci_read_config32(dev, PCI_VENDOR_ID));
178 pci_write_config32(dev, PCI_SUBSYSTEM_VENDOR_ID,
179 ((device & 0xffff) << 16) | (vendor & 0xffff));
183 static struct pci_operations sata_pci_ops = {
184 .set_subsystem = sata_set_subsystem,
187 static 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,
193 .enable = i82801gx_enable,
194 .ops_pci = &sata_pci_ops,
197 /* Desktop Non-AHCI and Non-RAID Mode */
198 /* 82801GB/GR/GDH (ICH7/ICH7R/ICH7DH) */
199 static const struct pci_driver i82801gx_sata_normal_driver __pci_driver = {
201 .vendor = PCI_VENDOR_ID_INTEL,
205 /* Mobile Non-AHCI and Non-RAID Mode */
206 /* 82801GBM/GHM (ICH7-M/ICH7-M DH) */
207 static const struct pci_driver i82801gx_sata_mobile_normal_driver __pci_driver = {
209 .vendor = PCI_VENDOR_ID_INTEL,
214 /* NOTE: Any of the below are not properly supported yet. */
216 /* Desktop AHCI Mode */
217 /* 82801GB/GR/GDH (ICH7/ICH7R/ICH7DH) */
218 static const struct pci_driver i82801gx_sata_ahci_driver __pci_driver = {
220 .vendor = PCI_VENDOR_ID_INTEL,
224 /* Desktop RAID mode */
225 /* 82801GB/GR/GDH (ICH7/ICH7R/ICH7DH) */
226 static const struct pci_driver i82801gx_sata_raid_driver __pci_driver = {
228 .vendor = PCI_VENDOR_ID_INTEL,
232 /* Mobile AHCI Mode */
233 /* 82801GBM/GHM (ICH7-M/ICH7-M DH) */
234 static const struct pci_driver i82801gx_sata_mobile_ahci_driver __pci_driver = {
236 .vendor = PCI_VENDOR_ID_INTEL,
240 /* ICH7M DH Raid Mode */
241 /* 82801GHM (ICH7-M DH) */
242 static const struct pci_driver i82801gx_sata_ich7dh_raid_driver __pci_driver = {
244 .vendor = PCI_VENDOR_ID_INTEL,