blob: 2e4115882b05524002eeb32005016025f3f252a0 [file] [log] [blame]
Stefan Reinauer8e073822012-04-04 00:07:22 +02001/*
2 * This file is part of the coreboot project.
3 *
4 * Copyright (C) 2008-2009 coresystems GmbH
5 *
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
9 * 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.
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 <arch/io.h>
22#include <console/console.h>
23#include <device/device.h>
24#include <device/pci.h>
25#include <device/pci_ids.h>
26#include "pch.h"
27
28typedef struct southbridge_intel_bd82x6x_config config_t;
29
30static void sata_init(struct device *dev)
31{
32 u32 reg32;
33 u16 reg16;
34 /* Get the chip configuration */
35 config_t *config = dev->chip_info;
36
37 printk(BIOS_DEBUG, "pch_sata: initializing...\n");
38
39 if (config == NULL) {
40 printk(BIOS_ERR, "pch_sata: error: device not in devicetree.cb!\n");
41 return;
42 }
43
44 /* SATA configuration */
45
46 /* Enable BARs */
47 pci_write_config16(dev, PCI_COMMAND, 0x0007);
48
49 if (config->ide_legacy_combined) {
50 printk(BIOS_DEBUG, "SATA controller in combined mode.\n");
Stefan Reinauer8e073822012-04-04 00:07:22 +020051
52 /* No AHCI: clear AHCI base */
53 pci_write_config32(dev, 0x24, 0x00000000);
54 /* And without AHCI BAR no memory decoding */
55 reg16 = pci_read_config16(dev, PCI_COMMAND);
56 reg16 &= ~PCI_COMMAND_MEMORY;
57 pci_write_config16(dev, PCI_COMMAND, reg16);
58
59 pci_write_config8(dev, 0x09, 0x80);
60
61 /* Set timings */
62 pci_write_config16(dev, IDE_TIM_PRI, IDE_DECODE_ENABLE |
63 IDE_ISP_5_CLOCKS | IDE_RCT_4_CLOCKS);
64 pci_write_config16(dev, IDE_TIM_SEC, IDE_DECODE_ENABLE |
65 IDE_ISP_3_CLOCKS | IDE_RCT_1_CLOCKS |
66 IDE_PPE0 | IDE_IE0 | IDE_TIME0);
67
68 /* Sync DMA */
69 pci_write_config16(dev, IDE_SDMA_CNT, IDE_SSDE0);
70 pci_write_config16(dev, IDE_SDMA_TIM, 0x0200);
71
72 /* Set IDE I/O Configuration */
73 reg32 = SIG_MODE_PRI_NORMAL | FAST_PCB1 | FAST_PCB0 | PCB1 | PCB0;
74 pci_write_config32(dev, IDE_CONFIG, reg32);
75
76 /* Port enable */
77 reg16 = pci_read_config16(dev, 0x92);
78 reg16 &= ~0x3f;
79 reg16 |= config->sata_port_map;
80 pci_write_config16(dev, 0x92, reg16);
81
82 /* SATA Initialization register */
83 pci_write_config32(dev, 0x94,
84 ((config->sata_port_map ^ 0x3f) << 24) | 0x183);
85 } else if(config->sata_ahci) {
86 u32 abar;
87
88 printk(BIOS_DEBUG, "SATA controller in AHCI mode.\n");
Stefan Reinauer8e073822012-04-04 00:07:22 +020089
90 /* Set Interrupt Line */
91 /* Interrupt Pin is set by D31IP.PIP */
92 pci_write_config8(dev, INTR_LN, 0x0a);
93
94 /* Set timings */
95 pci_write_config16(dev, IDE_TIM_PRI, IDE_DECODE_ENABLE |
96 IDE_ISP_3_CLOCKS | IDE_RCT_1_CLOCKS |
97 IDE_PPE0 | IDE_IE0 | IDE_TIME0);
98 pci_write_config16(dev, IDE_TIM_SEC, IDE_DECODE_ENABLE |
99 IDE_ISP_5_CLOCKS | IDE_RCT_4_CLOCKS);
100
101 /* Sync DMA */
102 pci_write_config16(dev, IDE_SDMA_CNT, IDE_PSDE0);
103 pci_write_config16(dev, IDE_SDMA_TIM, 0x0001);
104
105 /* Set IDE I/O Configuration */
106 reg32 = SIG_MODE_PRI_NORMAL | FAST_PCB1 | FAST_PCB0 | PCB1 | PCB0;
107 pci_write_config32(dev, IDE_CONFIG, reg32);
108
109 /* for AHCI, Port Enable is managed in memory mapped space */
110 reg16 = pci_read_config16(dev, 0x92);
111 reg16 &= ~0x3f; /* 6 ports SKU + ORM */
112 reg16 |= 0x8000 | config->sata_port_map;
113 pci_write_config16(dev, 0x92, reg16);
114
115 /* SATA Initialization register */
116 pci_write_config32(dev, 0x94,
117 ((config->sata_port_map ^ 0x3f) << 24) | 0x183);
118
119 /* Initialize AHCI memory-mapped space */
120 abar = pci_read_config32(dev, PCI_BASE_ADDRESS_5);
121 printk(BIOS_DEBUG, "ABAR: %08X\n", abar);
122 /* CAP (HBA Capabilities) : enable power management */
123 reg32 = read32(abar + 0x00);
124 reg32 |= 0x0c006000; // set PSC+SSC+SALP+SSS
125 reg32 &= ~0x00020060; // clear SXS+EMS+PMS
126 write32(abar + 0x00, reg32);
127 /* PI (Ports implemented) */
128 write32(abar + 0x0c, config->sata_port_map);
129 (void) read32(abar + 0x0c); /* Read back 1 */
130 (void) read32(abar + 0x0c); /* Read back 2 */
131 /* CAP2 (HBA Capabilities Extended)*/
132 reg32 = read32(abar + 0x24);
133 reg32 &= ~0x00000002;
134 write32(abar + 0x24, reg32);
135 /* VSP (Vendor Specific Register */
136 reg32 = read32(abar + 0xa0);
137 reg32 &= ~0x00000005;
138 write32(abar + 0xa0, reg32);
139 } else {
140 printk(BIOS_DEBUG, "SATA controller in plain mode.\n");
Stefan Reinauer8e073822012-04-04 00:07:22 +0200141
142 /* No AHCI: clear AHCI base */
143 pci_write_config32(dev, 0x24, 0x00000000);
144
145 /* And without AHCI BAR no memory decoding */
146 reg16 = pci_read_config16(dev, PCI_COMMAND);
147 reg16 &= ~PCI_COMMAND_MEMORY;
148 pci_write_config16(dev, PCI_COMMAND, reg16);
149
150 /* Native mode capable on both primary and secondary (0xa)
151 * or'ed with enabled (0x50) = 0xf
152 */
153 pci_write_config8(dev, 0x09, 0x8f);
154
155 /* Set Interrupt Line */
156 /* Interrupt Pin is set by D31IP.PIP */
157 pci_write_config8(dev, INTR_LN, 0xff);
158
159 /* Set timings */
160 pci_write_config16(dev, IDE_TIM_PRI, IDE_DECODE_ENABLE |
161 IDE_ISP_3_CLOCKS | IDE_RCT_1_CLOCKS |
162 IDE_PPE0 | IDE_IE0 | IDE_TIME0);
163 pci_write_config16(dev, IDE_TIM_SEC, IDE_DECODE_ENABLE |
164 IDE_SITRE | IDE_ISP_3_CLOCKS |
165 IDE_RCT_1_CLOCKS | IDE_IE0 | IDE_TIME0);
166
167 /* Sync DMA */
168 pci_write_config16(dev, IDE_SDMA_CNT, IDE_SSDE0 | IDE_PSDE0);
169 pci_write_config16(dev, IDE_SDMA_TIM, 0x0201);
170
171 /* Set IDE I/O Configuration */
172 reg32 = SIG_MODE_PRI_NORMAL | FAST_PCB1 | FAST_PCB0 | PCB1 | PCB0;
173 pci_write_config32(dev, IDE_CONFIG, reg32);
174
175 /* Port enable */
176 reg16 = pci_read_config16(dev, 0x92);
177 reg16 &= ~0x3f;
178 reg16 |= config->sata_port_map;
179 pci_write_config16(dev, 0x92, reg16);
180
181 /* SATA Initialization register */
182 pci_write_config32(dev, 0x94,
183 ((config->sata_port_map ^ 0x3f) << 24) | 0x183);
184 }
Duncan Lauriecfb64bd2012-07-16 16:16:31 -0700185
186 /* Set Gen3 Transmitter settings if needed */
187 if (config->sata_port0_gen3_tx)
188 pch_iobp_update(SATA_IOBP_SP0G3IR, 0,
189 config->sata_port0_gen3_tx);
190
191 if (config->sata_port1_gen3_tx)
192 pch_iobp_update(SATA_IOBP_SP1G3IR, 0,
193 config->sata_port1_gen3_tx);
Stefan Reinauer8e073822012-04-04 00:07:22 +0200194}
195
Stefan Reinauer816d0812012-04-30 16:42:07 -0700196static void sata_enable(device_t dev)
197{
198 /* Get the chip configuration */
199 config_t *config = dev->chip_info;
200 u16 map = 0;
201
202 if (!config)
203 return;
204
205 /*
206 * Set SATA controller mode early so the resource allocator can
207 * properly assign IO/Memory resources for the controller.
208 */
209 if (config->sata_ahci)
210 map = 0x0060;
211
212 map |= (config->sata_port_map ^ 0x3f) << 8;
213
214 pci_write_config16(dev, 0x90, map);
215}
216
Stefan Reinauer8e073822012-04-04 00:07:22 +0200217static void sata_set_subsystem(device_t dev, unsigned vendor, unsigned device)
218{
219 if (!vendor || !device) {
220 pci_write_config32(dev, PCI_SUBSYSTEM_VENDOR_ID,
221 pci_read_config32(dev, PCI_VENDOR_ID));
222 } else {
223 pci_write_config32(dev, PCI_SUBSYSTEM_VENDOR_ID,
224 ((device & 0xffff) << 16) | (vendor & 0xffff));
225 }
226}
227
228static struct pci_operations sata_pci_ops = {
229 .set_subsystem = sata_set_subsystem,
230};
231
232static struct device_operations sata_ops = {
233 .read_resources = pci_dev_read_resources,
234 .set_resources = pci_dev_set_resources,
235 .enable_resources = pci_dev_enable_resources,
236 .init = sata_init,
Stefan Reinauer816d0812012-04-30 16:42:07 -0700237 .enable = sata_enable,
Stefan Reinauer8e073822012-04-04 00:07:22 +0200238 .scan_bus = 0,
239 .ops_pci = &sata_pci_ops,
240};
241
Stefan Reinauer9a380ab2012-06-22 13:16:11 -0700242static const unsigned short pci_device_ids[] = { 0x1c00, 0x1c01, 0x1c02, 0x1c03,
243 0x1e00, 0x1e01, 0x1e02, 0x1e03,
244 0 };
245
246static const struct pci_driver pch_sata __pci_driver = {
247 .ops = &sata_ops,
248 .vendor = PCI_VENDOR_ID_INTEL,
249 .devices = pci_device_ids,
Stefan Reinauer8e073822012-04-04 00:07:22 +0200250};
251