2 * This file is part of the coreboot project.
4 * Copyright (C) 2008 coresystems GmbH
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; either version 2 of the License, or
9 * (at your option) any later version.
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)
32 /* Get the chip configuration */
33 config_t *config = dev->chip_info;
35 printk_debug("i82801gx_sata: initializing...\n");
36 /* SATA configuration */
39 pci_write_config16(dev, 0x04, 0x0007);
41 if (config->ide_legacy_combined) {
42 pci_write_config8(dev, 0x09, 0x80);
45 pci_write_config16(dev, IDE_TIM_PRI, 0x8000);
46 pci_write_config16(dev, IDE_TIM_SEC, 0xa307);
49 pci_write_config16(dev, 0x48, 0x0004);
50 pci_write_config16(dev, 0x4a, 0x0200);
52 /* Combine IDE - SATA configuration */
53 pci_write_config8(dev, 0x90, 0x02);
55 /* Port 0 & 1 enable */
56 pci_write_config8(dev, 0x92, 0x0f);
58 /* SATA Initialization register */
59 pci_write_config32(dev, 0x94, 0x40000180);
60 } else if(config->sata_ahci) {
61 /* Allow both Legacy and Native mode */
62 pci_write_config8(dev, 0x09, 0x8f);
64 /* Set Interrupt Line */
65 /* Interrupt Pin is set by D31IP.PIP */
66 pci_write_config8(dev, INTR_LN, 0x0a);
69 pci_write_config16(dev, IDE_TIM_PRI, 0xa307);
70 pci_write_config16(dev, IDE_TIM_SEC, 0x8000);
73 pci_write_config16(dev, 0x48, 0x0001);
74 pci_write_config16(dev, 0x4a, 0x0001);
76 /* Set IDE I/O Configuration */
77 reg32 = SIG_MODE_NORMAL | FAST_PCB1 | FAST_PCB0 | PCB1 | PCB0;
78 pci_write_config32(dev, IDE_CONFIG, reg32);
80 /* Set Sata Controller Mode. */
81 pci_write_config8(dev, 0x90, 0xc0); // WTF - Reserved?
83 /* Port 0 & 1 enable */
84 pci_write_config8(dev, 0x92, 0x0f);
86 /* SATA Initialization register */
87 pci_write_config32(dev, 0x94, 0x1a000180);
89 /* Native mode capable on both primary and secondary (0xa)
90 * or'ed with enabled (0x50) = 0xf
92 pci_write_config8(dev, 0x09, 0x8f);
94 /* Set Interrupt Line */
95 /* Interrupt Pin is set by D31IP.PIP */
96 pci_write_config8(dev, INTR_LN, 0xff);
99 pci_write_config16(dev, IDE_TIM_PRI, 0xa307);
100 pci_write_config16(dev, IDE_TIM_SEC, 0xe303);
103 pci_write_config16(dev, 0x48, 0x0005);
104 pci_write_config16(dev, 0x4a, 0x0201);
106 /* Set IDE I/O Configuration */
107 reg32 = SIG_MODE_NORMAL | FAST_PCB1 | FAST_PCB0 | PCB1 | PCB0;
108 pci_write_config32(dev, IDE_CONFIG, reg32);
110 /* Set Sata Controller Mode. */
111 pci_write_config8(dev, 0x90, 0x02);
113 /* Port 0 & 1 enable XXX */
114 pci_write_config8(dev, 0x92, 0x15);
116 /* SATA Initialization register */
117 pci_write_config32(dev, 0x94, 0x1a000180);
120 /* All configurations need this SATA initialization sequence */
121 pci_write_config8(dev, 0xa0, 0x40);
122 pci_write_config8(dev, 0xa6, 0x22);
123 pci_write_config8(dev, 0xa0, 0x78);
124 pci_write_config8(dev, 0xa6, 0x22);
125 pci_write_config8(dev, 0xa0, 0x88);
126 reg32 = pci_read_config32(dev, 0xa4);
129 pci_write_config32(dev, 0xa4, reg32);
130 pci_write_config8(dev, 0xa0, 0x8c);
131 reg32 = pci_read_config32(dev, 0xa4);
134 pci_write_config32(dev, 0xa4, reg32);
135 pci_write_config8(dev, 0xa0, 0x00);
138 static struct device_operations sata_ops = {
139 .read_resources = pci_dev_read_resources,
140 .set_resources = pci_dev_set_resources,
141 .enable_resources = pci_dev_enable_resources,
144 .enable = i82801gx_enable,
147 /* Desktop Non-AHCI and Non-RAID Mode */
148 static const struct pci_driver i82801gx_sata_normal_driver __pci_driver = {
150 .vendor = PCI_VENDOR_ID_INTEL,
154 /* NOTE: Any of the below are not properly supported yet */
156 /* Desktop AHCI Mode */
157 static const struct pci_driver i82801gx_sata_ahci_driver __pci_driver = {
159 .vendor = PCI_VENDOR_ID_INTEL,
163 /* Desktop RAID mode */
164 static const struct pci_driver i82801gx_sata_raid_driver __pci_driver = {
166 .vendor = PCI_VENDOR_ID_INTEL,
170 /* Mobile Non-AHCI and Non-RAID Mode */
171 static const struct pci_driver i82801gx_sata_mobile_normal_driver __pci_driver = {
173 .vendor = PCI_VENDOR_ID_INTEL,
177 /* Mobile AHCI Mode */
178 static const struct pci_driver i82801gx_sata_mobile_ahci_driver __pci_driver = {
180 .vendor = PCI_VENDOR_ID_INTEL,
184 /* ICH7M DH Raid Mode */
185 static const struct pci_driver i82801gx_sata_ich7dh_raid_driver __pci_driver = {
187 .vendor = PCI_VENDOR_ID_INTEL,