2008-10-29 05:46:52 +01:00
|
|
|
/*
|
|
|
|
* This file is part of the coreboot project.
|
|
|
|
*
|
2009-01-20 23:53:10 +01:00
|
|
|
* Copyright (C) 2008-2009 coresystems GmbH
|
2008-10-29 05:46:52 +01:00
|
|
|
*
|
2009-03-11 15:54:18 +01:00
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License as
|
|
|
|
* published by the Free Software Foundation; version 2 of
|
|
|
|
* the License.
|
2008-10-29 05:46:52 +01:00
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <console/console.h>
|
|
|
|
#include <device/device.h>
|
|
|
|
#include <device/pci.h>
|
|
|
|
#include <device/pci_ids.h>
|
|
|
|
#include "i82801gx.h"
|
|
|
|
|
|
|
|
typedef struct southbridge_intel_i82801gx_config config_t;
|
|
|
|
|
|
|
|
static void sata_init(struct device *dev)
|
|
|
|
{
|
|
|
|
u32 reg32;
|
2009-03-11 15:54:18 +01:00
|
|
|
u16 reg16;
|
2008-10-29 05:46:52 +01:00
|
|
|
/* Get the chip configuration */
|
|
|
|
config_t *config = dev->chip_info;
|
|
|
|
|
|
|
|
printk_debug("i82801gx_sata: initializing...\n");
|
2009-03-11 15:54:18 +01:00
|
|
|
|
2009-07-21 23:50:34 +02:00
|
|
|
if (config == NULL) {
|
2009-03-11 15:54:18 +01:00
|
|
|
printk_err("i82801gx_sata: error: device not in Config.lb!\n");
|
2009-07-21 23:50:34 +02:00
|
|
|
return;
|
|
|
|
}
|
2009-03-11 15:54:18 +01:00
|
|
|
|
2008-10-29 05:46:52 +01:00
|
|
|
/* SATA configuration */
|
|
|
|
|
|
|
|
/* Enable BARs */
|
2009-03-11 15:54:18 +01:00
|
|
|
pci_write_config16(dev, PCI_COMMAND, 0x0007);
|
2008-10-29 05:46:52 +01:00
|
|
|
|
|
|
|
if (config->ide_legacy_combined) {
|
2009-03-11 15:54:18 +01:00
|
|
|
printk_debug("SATA controller in combined mode.\n");
|
|
|
|
/* No AHCI: clear AHCI base */
|
|
|
|
pci_write_config32(dev, 0x24, 0x00000000);
|
|
|
|
/* And without AHCI BAR no memory decoding */
|
|
|
|
reg16 = pci_read_config16(dev, PCI_COMMAND);
|
|
|
|
reg16 &= ~PCI_COMMAND_MEMORY;
|
|
|
|
pci_write_config16(dev, PCI_COMMAND, reg16);
|
|
|
|
|
2008-10-29 05:46:52 +01:00
|
|
|
pci_write_config8(dev, 0x09, 0x80);
|
|
|
|
|
|
|
|
/* Set timings */
|
2009-07-21 23:50:34 +02:00
|
|
|
pci_write_config16(dev, IDE_TIM_PRI, IDE_DECODE_ENABLE |
|
|
|
|
IDE_ISP_5_CLOCKS | IDE_RCT_4_CLOCKS);
|
|
|
|
pci_write_config16(dev, IDE_TIM_SEC, IDE_DECODE_ENABLE |
|
|
|
|
IDE_ISP_3_CLOCKS | IDE_RCT_1_CLOCKS |
|
|
|
|
IDE_PPE0 | IDE_IE0 | IDE_TIME0);
|
2008-10-29 05:46:52 +01:00
|
|
|
|
|
|
|
/* Sync DMA */
|
2009-07-21 23:50:34 +02:00
|
|
|
pci_write_config16(dev, IDE_SDMA_CNT, IDE_SSDE0);
|
|
|
|
pci_write_config16(dev, IDE_SDMA_TIM, 0x0200);
|
2008-10-29 05:46:52 +01:00
|
|
|
|
2009-03-11 15:54:18 +01:00
|
|
|
/* Set IDE I/O Configuration */
|
|
|
|
reg32 = SIG_MODE_NORMAL | FAST_PCB1 | FAST_PCB0 | PCB1 | PCB0;
|
|
|
|
pci_write_config32(dev, IDE_CONFIG, reg32);
|
|
|
|
|
2008-10-29 05:46:52 +01:00
|
|
|
/* Combine IDE - SATA configuration */
|
|
|
|
pci_write_config8(dev, 0x90, 0x02);
|
|
|
|
|
|
|
|
/* Port 0 & 1 enable */
|
|
|
|
pci_write_config8(dev, 0x92, 0x0f);
|
|
|
|
|
|
|
|
/* SATA Initialization register */
|
2009-03-11 15:54:18 +01:00
|
|
|
pci_write_config32(dev, 0x94, 0x5a000180);
|
2008-10-29 05:46:52 +01:00
|
|
|
} else if(config->sata_ahci) {
|
2009-03-11 15:54:18 +01:00
|
|
|
printk_debug("SATA controller in AHCI mode.\n");
|
2008-10-29 05:46:52 +01:00
|
|
|
/* Allow both Legacy and Native mode */
|
|
|
|
pci_write_config8(dev, 0x09, 0x8f);
|
|
|
|
|
|
|
|
/* Set Interrupt Line */
|
|
|
|
/* Interrupt Pin is set by D31IP.PIP */
|
|
|
|
pci_write_config8(dev, INTR_LN, 0x0a);
|
|
|
|
|
|
|
|
/* Set timings */
|
2009-07-21 23:50:34 +02:00
|
|
|
pci_write_config16(dev, IDE_TIM_PRI, IDE_DECODE_ENABLE |
|
|
|
|
IDE_ISP_3_CLOCKS | IDE_RCT_1_CLOCKS |
|
|
|
|
IDE_PPE0 | IDE_IE0 | IDE_TIME0);
|
|
|
|
pci_write_config16(dev, IDE_TIM_SEC, IDE_DECODE_ENABLE |
|
|
|
|
IDE_ISP_5_CLOCKS | IDE_RCT_4_CLOCKS);
|
2008-10-29 05:46:52 +01:00
|
|
|
|
|
|
|
/* Sync DMA */
|
2009-07-21 23:50:34 +02:00
|
|
|
pci_write_config16(dev, IDE_SDMA_CNT, IDE_PSDE0);
|
|
|
|
pci_write_config16(dev, IDE_SDMA_TIM, 0x0001);
|
2008-10-29 05:46:52 +01:00
|
|
|
|
|
|
|
/* Set IDE I/O Configuration */
|
|
|
|
reg32 = SIG_MODE_NORMAL | FAST_PCB1 | FAST_PCB0 | PCB1 | PCB0;
|
|
|
|
pci_write_config32(dev, IDE_CONFIG, reg32);
|
|
|
|
|
|
|
|
/* Set Sata Controller Mode. */
|
|
|
|
pci_write_config8(dev, 0x90, 0xc0); // WTF - Reserved?
|
|
|
|
|
|
|
|
/* Port 0 & 1 enable */
|
|
|
|
pci_write_config8(dev, 0x92, 0x0f);
|
|
|
|
|
|
|
|
/* SATA Initialization register */
|
|
|
|
pci_write_config32(dev, 0x94, 0x1a000180);
|
|
|
|
} else {
|
2009-03-11 15:54:18 +01:00
|
|
|
printk_debug("SATA controller in plain mode.\n");
|
|
|
|
/* Set Sata Controller Mode. No Mapping(?) */
|
|
|
|
pci_write_config8(dev, 0x90, 0x00);
|
|
|
|
|
|
|
|
/* No AHCI: clear AHCI base */
|
|
|
|
pci_write_config32(dev, 0x24, 0x00000000);
|
|
|
|
|
|
|
|
/* And without AHCI BAR no memory decoding */
|
|
|
|
reg16 = pci_read_config16(dev, PCI_COMMAND);
|
|
|
|
reg16 &= ~PCI_COMMAND_MEMORY;
|
|
|
|
pci_write_config16(dev, PCI_COMMAND, reg16);
|
|
|
|
|
2008-10-29 05:46:52 +01:00
|
|
|
/* Native mode capable on both primary and secondary (0xa)
|
|
|
|
* or'ed with enabled (0x50) = 0xf
|
|
|
|
*/
|
|
|
|
pci_write_config8(dev, 0x09, 0x8f);
|
|
|
|
|
|
|
|
/* Set Interrupt Line */
|
|
|
|
/* Interrupt Pin is set by D31IP.PIP */
|
|
|
|
pci_write_config8(dev, INTR_LN, 0xff);
|
2009-08-12 18:08:05 +02:00
|
|
|
|
2008-10-29 05:46:52 +01:00
|
|
|
/* Set timings */
|
2009-07-21 23:50:34 +02:00
|
|
|
pci_write_config16(dev, IDE_TIM_PRI, IDE_DECODE_ENABLE |
|
|
|
|
IDE_ISP_3_CLOCKS | IDE_RCT_1_CLOCKS |
|
|
|
|
IDE_PPE0 | IDE_IE0 | IDE_TIME0);
|
|
|
|
pci_write_config16(dev, IDE_TIM_SEC, IDE_DECODE_ENABLE |
|
2009-08-12 18:08:05 +02:00
|
|
|
IDE_SITRE | IDE_ISP_3_CLOCKS |
|
2009-07-21 23:50:34 +02:00
|
|
|
IDE_RCT_1_CLOCKS | IDE_IE0 | IDE_TIME0);
|
2009-08-12 18:08:05 +02:00
|
|
|
|
2008-10-29 05:46:52 +01:00
|
|
|
/* Sync DMA */
|
2009-07-21 23:50:34 +02:00
|
|
|
pci_write_config16(dev, IDE_SDMA_CNT, IDE_SSDE0 | IDE_PSDE0);
|
|
|
|
pci_write_config16(dev, IDE_SDMA_TIM, 0x0201);
|
2009-08-12 18:08:05 +02:00
|
|
|
|
2008-10-29 05:46:52 +01:00
|
|
|
/* Set IDE I/O Configuration */
|
|
|
|
reg32 = SIG_MODE_NORMAL | FAST_PCB1 | FAST_PCB0 | PCB1 | PCB0;
|
|
|
|
pci_write_config32(dev, IDE_CONFIG, reg32);
|
2009-08-12 18:08:05 +02:00
|
|
|
|
2008-10-29 05:46:52 +01:00
|
|
|
/* Port 0 & 1 enable XXX */
|
|
|
|
pci_write_config8(dev, 0x92, 0x15);
|
2009-08-12 18:08:05 +02:00
|
|
|
|
2008-10-29 05:46:52 +01:00
|
|
|
/* SATA Initialization register */
|
|
|
|
pci_write_config32(dev, 0x94, 0x1a000180);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* All configurations need this SATA initialization sequence */
|
|
|
|
pci_write_config8(dev, 0xa0, 0x40);
|
|
|
|
pci_write_config8(dev, 0xa6, 0x22);
|
|
|
|
pci_write_config8(dev, 0xa0, 0x78);
|
|
|
|
pci_write_config8(dev, 0xa6, 0x22);
|
|
|
|
pci_write_config8(dev, 0xa0, 0x88);
|
|
|
|
reg32 = pci_read_config32(dev, 0xa4);
|
|
|
|
reg32 &= 0xc0c0c0c0;
|
|
|
|
reg32 |= 0x1b1b1212;
|
|
|
|
pci_write_config32(dev, 0xa4, reg32);
|
|
|
|
pci_write_config8(dev, 0xa0, 0x8c);
|
|
|
|
reg32 = pci_read_config32(dev, 0xa4);
|
|
|
|
reg32 &= 0xc0c0ff00;
|
|
|
|
reg32 |= 0x121200aa;
|
|
|
|
pci_write_config32(dev, 0xa4, reg32);
|
|
|
|
pci_write_config8(dev, 0xa0, 0x00);
|
2009-01-20 23:53:10 +01:00
|
|
|
|
|
|
|
pci_write_config8(dev, PCI_INTERRUPT_LINE, 0);
|
2009-03-11 15:54:18 +01:00
|
|
|
|
|
|
|
/* Sata Initialization Register */
|
|
|
|
reg32 = pci_read_config32(dev, 0x94);
|
|
|
|
reg32 |= (1 << 30); // due to some bug
|
|
|
|
pci_write_config32(dev, 0x94, reg32);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void sata_set_subsystem(device_t dev, unsigned vendor, unsigned device)
|
|
|
|
{
|
|
|
|
if (!vendor || !device) {
|
|
|
|
pci_write_config32(dev, PCI_SUBSYSTEM_VENDOR_ID,
|
|
|
|
pci_read_config32(dev, PCI_VENDOR_ID));
|
|
|
|
} else {
|
|
|
|
pci_write_config32(dev, PCI_SUBSYSTEM_VENDOR_ID,
|
|
|
|
((device & 0xffff) << 16) | (vendor & 0xffff));
|
|
|
|
}
|
2008-10-29 05:46:52 +01:00
|
|
|
}
|
|
|
|
|
2009-03-11 15:54:18 +01:00
|
|
|
static struct pci_operations sata_pci_ops = {
|
|
|
|
.set_subsystem = sata_set_subsystem,
|
|
|
|
};
|
|
|
|
|
2008-10-29 05:46:52 +01:00
|
|
|
static struct device_operations sata_ops = {
|
|
|
|
.read_resources = pci_dev_read_resources,
|
|
|
|
.set_resources = pci_dev_set_resources,
|
|
|
|
.enable_resources = pci_dev_enable_resources,
|
|
|
|
.init = sata_init,
|
|
|
|
.scan_bus = 0,
|
|
|
|
.enable = i82801gx_enable,
|
2009-03-11 15:54:18 +01:00
|
|
|
.ops_pci = &sata_pci_ops,
|
2008-10-29 05:46:52 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
/* Desktop Non-AHCI and Non-RAID Mode */
|
2008-10-29 14:51:31 +01:00
|
|
|
/* 82801GB/GR/GDH (ICH7/ICH7R/ICH7DH) */
|
2008-10-29 05:46:52 +01:00
|
|
|
static const struct pci_driver i82801gx_sata_normal_driver __pci_driver = {
|
|
|
|
.ops = &sata_ops,
|
|
|
|
.vendor = PCI_VENDOR_ID_INTEL,
|
2008-10-31 19:41:09 +01:00
|
|
|
.device = 0x27c0,
|
2008-10-29 05:46:52 +01:00
|
|
|
};
|
|
|
|
|
2009-03-11 15:54:18 +01:00
|
|
|
/* Mobile Non-AHCI and Non-RAID Mode */
|
|
|
|
/* 82801GBM/GHM (ICH7-M/ICH7-M DH) */
|
|
|
|
static const struct pci_driver i82801gx_sata_mobile_normal_driver __pci_driver = {
|
|
|
|
.ops = &sata_ops,
|
|
|
|
.vendor = PCI_VENDOR_ID_INTEL,
|
|
|
|
.device = 0x27c4,
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2008-10-29 14:51:31 +01:00
|
|
|
/* NOTE: Any of the below are not properly supported yet. */
|
2008-10-29 05:46:52 +01:00
|
|
|
|
|
|
|
/* Desktop AHCI Mode */
|
2008-10-29 14:51:31 +01:00
|
|
|
/* 82801GB/GR/GDH (ICH7/ICH7R/ICH7DH) */
|
2008-10-29 05:46:52 +01:00
|
|
|
static const struct pci_driver i82801gx_sata_ahci_driver __pci_driver = {
|
|
|
|
.ops = &sata_ops,
|
|
|
|
.vendor = PCI_VENDOR_ID_INTEL,
|
2008-10-31 19:41:09 +01:00
|
|
|
.device = 0x27c1,
|
2008-10-29 05:46:52 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
/* Desktop RAID mode */
|
2008-10-29 14:51:31 +01:00
|
|
|
/* 82801GB/GR/GDH (ICH7/ICH7R/ICH7DH) */
|
2008-10-29 05:46:52 +01:00
|
|
|
static const struct pci_driver i82801gx_sata_raid_driver __pci_driver = {
|
|
|
|
.ops = &sata_ops,
|
|
|
|
.vendor = PCI_VENDOR_ID_INTEL,
|
2008-10-31 19:41:09 +01:00
|
|
|
.device = 0x27c3,
|
2008-10-29 05:46:52 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
/* Mobile AHCI Mode */
|
2008-10-29 14:51:31 +01:00
|
|
|
/* 82801GBM/GHM (ICH7-M/ICH7-M DH) */
|
2008-10-29 05:46:52 +01:00
|
|
|
static const struct pci_driver i82801gx_sata_mobile_ahci_driver __pci_driver = {
|
|
|
|
.ops = &sata_ops,
|
|
|
|
.vendor = PCI_VENDOR_ID_INTEL,
|
2008-10-31 19:41:09 +01:00
|
|
|
.device = 0x27c5,
|
2008-10-29 05:46:52 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
/* ICH7M DH Raid Mode */
|
2008-10-29 14:51:31 +01:00
|
|
|
/* 82801GHM (ICH7-M DH) */
|
2008-10-29 05:46:52 +01:00
|
|
|
static const struct pci_driver i82801gx_sata_ich7dh_raid_driver __pci_driver = {
|
|
|
|
.ops = &sata_ops,
|
|
|
|
.vendor = PCI_VENDOR_ID_INTEL,
|
2008-10-31 19:41:09 +01:00
|
|
|
.device = 0x27c6,
|
2008-10-29 05:46:52 +01:00
|
|
|
};
|