2014-11-15 01:18:38 +00:00
|
|
|
/*
|
|
|
|
* From Coreboot
|
|
|
|
* Copyright (C) 2008-2009 coresystems GmbH
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: GPL-2.0
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <common.h>
|
2016-01-17 23:11:35 +00:00
|
|
|
#include <dm.h>
|
2014-11-15 01:18:38 +00:00
|
|
|
#include <fdtdec.h>
|
|
|
|
#include <asm/io.h>
|
2016-03-16 13:44:36 +00:00
|
|
|
#include <asm/pch_common.h>
|
2014-11-15 01:18:38 +00:00
|
|
|
#include <asm/pci.h>
|
|
|
|
#include <asm/arch/pch.h>
|
|
|
|
|
2016-01-17 23:11:35 +00:00
|
|
|
DECLARE_GLOBAL_DATA_PTR;
|
|
|
|
|
2016-01-17 23:11:38 +00:00
|
|
|
static void common_sata_init(struct udevice *dev, unsigned int port_map)
|
2014-11-15 01:18:38 +00:00
|
|
|
{
|
|
|
|
u32 reg32;
|
|
|
|
u16 reg16;
|
|
|
|
|
|
|
|
/* Set IDE I/O Configuration */
|
|
|
|
reg32 = SIG_MODE_PRI_NORMAL | FAST_PCB1 | FAST_PCB0 | PCB1 | PCB0;
|
2016-01-17 23:11:38 +00:00
|
|
|
dm_pci_write_config32(dev, IDE_CONFIG, reg32);
|
2014-11-15 01:18:38 +00:00
|
|
|
|
|
|
|
/* Port enable */
|
2016-01-17 23:11:38 +00:00
|
|
|
dm_pci_read_config16(dev, 0x92, ®16);
|
2014-11-15 01:18:38 +00:00
|
|
|
reg16 &= ~0x3f;
|
|
|
|
reg16 |= port_map;
|
2016-01-17 23:11:38 +00:00
|
|
|
dm_pci_write_config16(dev, 0x92, reg16);
|
2014-11-15 01:18:38 +00:00
|
|
|
|
|
|
|
/* SATA Initialization register */
|
|
|
|
port_map &= 0xff;
|
2016-01-17 23:11:38 +00:00
|
|
|
dm_pci_write_config32(dev, 0x94, ((port_map ^ 0x3f) << 24) | 0x183);
|
2014-11-15 01:18:38 +00:00
|
|
|
}
|
|
|
|
|
2016-01-17 23:11:52 +00:00
|
|
|
static void bd82x6x_sata_init(struct udevice *dev, struct udevice *pch)
|
2014-11-15 01:18:38 +00:00
|
|
|
{
|
|
|
|
unsigned int port_map, speed_support, port_tx;
|
2016-01-17 23:11:38 +00:00
|
|
|
const void *blob = gd->fdt_blob;
|
|
|
|
int node = dev->of_offset;
|
2014-11-15 01:18:38 +00:00
|
|
|
const char *mode;
|
|
|
|
u32 reg32;
|
|
|
|
u16 reg16;
|
|
|
|
|
|
|
|
debug("SATA: Initializing...\n");
|
|
|
|
|
|
|
|
/* SATA configuration */
|
|
|
|
port_map = fdtdec_get_int(blob, node, "intel,sata-port-map", 0);
|
|
|
|
speed_support = fdtdec_get_int(blob, node,
|
|
|
|
"sata_interface_speed_support", 0);
|
|
|
|
|
|
|
|
mode = fdt_getprop(blob, node, "intel,sata-mode", NULL);
|
|
|
|
if (!mode || !strcmp(mode, "ahci")) {
|
|
|
|
u32 abar;
|
|
|
|
|
|
|
|
debug("SATA: Controller in AHCI mode\n");
|
|
|
|
|
|
|
|
/* Set timings */
|
2016-01-17 23:11:38 +00:00
|
|
|
dm_pci_write_config16(dev, IDE_TIM_PRI, IDE_DECODE_ENABLE |
|
2014-11-15 01:18:38 +00:00
|
|
|
IDE_ISP_3_CLOCKS | IDE_RCT_1_CLOCKS |
|
|
|
|
IDE_PPE0 | IDE_IE0 | IDE_TIME0);
|
2016-01-17 23:11:38 +00:00
|
|
|
dm_pci_write_config16(dev, IDE_TIM_SEC, IDE_DECODE_ENABLE |
|
2014-11-15 01:18:38 +00:00
|
|
|
IDE_ISP_5_CLOCKS | IDE_RCT_4_CLOCKS);
|
|
|
|
|
|
|
|
/* Sync DMA */
|
2016-01-17 23:11:38 +00:00
|
|
|
dm_pci_write_config16(dev, IDE_SDMA_CNT, IDE_PSDE0);
|
|
|
|
dm_pci_write_config16(dev, IDE_SDMA_TIM, 0x0001);
|
2014-11-15 01:18:38 +00:00
|
|
|
|
|
|
|
common_sata_init(dev, 0x8000 | port_map);
|
|
|
|
|
|
|
|
/* Initialize AHCI memory-mapped space */
|
2016-01-17 23:11:38 +00:00
|
|
|
abar = dm_pci_read_bar32(dev, 5);
|
2014-11-15 01:18:38 +00:00
|
|
|
debug("ABAR: %08X\n", abar);
|
|
|
|
/* CAP (HBA Capabilities) : enable power management */
|
|
|
|
reg32 = readl(abar + 0x00);
|
|
|
|
reg32 |= 0x0c006000; /* set PSC+SSC+SALP+SSS */
|
|
|
|
reg32 &= ~0x00020060; /* clear SXS+EMS+PMS */
|
|
|
|
/* Set ISS, if available */
|
|
|
|
if (speed_support) {
|
|
|
|
reg32 &= ~0x00f00000;
|
|
|
|
reg32 |= (speed_support & 0x03) << 20;
|
|
|
|
}
|
|
|
|
writel(reg32, abar + 0x00);
|
|
|
|
/* PI (Ports implemented) */
|
|
|
|
writel(port_map, abar + 0x0c);
|
|
|
|
(void) readl(abar + 0x0c); /* Read back 1 */
|
|
|
|
(void) readl(abar + 0x0c); /* Read back 2 */
|
|
|
|
/* CAP2 (HBA Capabilities Extended)*/
|
|
|
|
reg32 = readl(abar + 0x24);
|
|
|
|
reg32 &= ~0x00000002;
|
|
|
|
writel(reg32, abar + 0x24);
|
|
|
|
/* VSP (Vendor Specific Register */
|
|
|
|
reg32 = readl(abar + 0xa0);
|
|
|
|
reg32 &= ~0x00000005;
|
|
|
|
writel(reg32, abar + 0xa0);
|
|
|
|
} else if (!strcmp(mode, "combined")) {
|
|
|
|
debug("SATA: Controller in combined mode\n");
|
|
|
|
|
|
|
|
/* No AHCI: clear AHCI base */
|
2016-01-17 23:11:38 +00:00
|
|
|
dm_pci_write_bar32(dev, 5, 0x00000000);
|
2014-11-15 01:18:38 +00:00
|
|
|
/* And without AHCI BAR no memory decoding */
|
2016-01-17 23:11:38 +00:00
|
|
|
dm_pci_read_config16(dev, PCI_COMMAND, ®16);
|
2014-11-15 01:18:38 +00:00
|
|
|
reg16 &= ~PCI_COMMAND_MEMORY;
|
2016-01-17 23:11:38 +00:00
|
|
|
dm_pci_write_config16(dev, PCI_COMMAND, reg16);
|
2014-11-15 01:18:38 +00:00
|
|
|
|
2016-01-17 23:11:38 +00:00
|
|
|
dm_pci_write_config8(dev, 0x09, 0x80);
|
2014-11-15 01:18:38 +00:00
|
|
|
|
|
|
|
/* Set timings */
|
2016-01-17 23:11:38 +00:00
|
|
|
dm_pci_write_config16(dev, IDE_TIM_PRI, IDE_DECODE_ENABLE |
|
2014-11-15 01:18:38 +00:00
|
|
|
IDE_ISP_5_CLOCKS | IDE_RCT_4_CLOCKS);
|
2016-01-17 23:11:38 +00:00
|
|
|
dm_pci_write_config16(dev, IDE_TIM_SEC, IDE_DECODE_ENABLE |
|
2014-11-15 01:18:38 +00:00
|
|
|
IDE_ISP_3_CLOCKS | IDE_RCT_1_CLOCKS |
|
|
|
|
IDE_PPE0 | IDE_IE0 | IDE_TIME0);
|
|
|
|
|
|
|
|
/* Sync DMA */
|
2016-01-17 23:11:38 +00:00
|
|
|
dm_pci_write_config16(dev, IDE_SDMA_CNT, IDE_SSDE0);
|
|
|
|
dm_pci_write_config16(dev, IDE_SDMA_TIM, 0x0200);
|
2014-11-15 01:18:38 +00:00
|
|
|
|
|
|
|
common_sata_init(dev, port_map);
|
|
|
|
} else {
|
|
|
|
debug("SATA: Controller in plain-ide mode\n");
|
|
|
|
|
|
|
|
/* No AHCI: clear AHCI base */
|
2016-01-17 23:11:38 +00:00
|
|
|
dm_pci_write_bar32(dev, 5, 0x00000000);
|
2014-11-15 01:18:38 +00:00
|
|
|
|
|
|
|
/* And without AHCI BAR no memory decoding */
|
2016-01-17 23:11:38 +00:00
|
|
|
dm_pci_read_config16(dev, PCI_COMMAND, ®16);
|
2014-11-15 01:18:38 +00:00
|
|
|
reg16 &= ~PCI_COMMAND_MEMORY;
|
2016-01-17 23:11:38 +00:00
|
|
|
dm_pci_write_config16(dev, PCI_COMMAND, reg16);
|
2014-11-15 01:18:38 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Native mode capable on both primary and secondary (0xa)
|
|
|
|
* OR'ed with enabled (0x50) = 0xf
|
|
|
|
*/
|
2016-01-17 23:11:38 +00:00
|
|
|
dm_pci_write_config8(dev, 0x09, 0x8f);
|
2014-11-15 01:18:38 +00:00
|
|
|
|
|
|
|
/* Set timings */
|
2016-01-17 23:11:38 +00:00
|
|
|
dm_pci_write_config16(dev, IDE_TIM_PRI, IDE_DECODE_ENABLE |
|
2014-11-15 01:18:38 +00:00
|
|
|
IDE_ISP_3_CLOCKS | IDE_RCT_1_CLOCKS |
|
|
|
|
IDE_PPE0 | IDE_IE0 | IDE_TIME0);
|
2016-01-17 23:11:38 +00:00
|
|
|
dm_pci_write_config16(dev, IDE_TIM_SEC, IDE_DECODE_ENABLE |
|
2014-11-15 01:18:38 +00:00
|
|
|
IDE_SITRE | IDE_ISP_3_CLOCKS |
|
|
|
|
IDE_RCT_1_CLOCKS | IDE_IE0 | IDE_TIME0);
|
|
|
|
|
|
|
|
/* Sync DMA */
|
2016-01-17 23:11:38 +00:00
|
|
|
dm_pci_write_config16(dev, IDE_SDMA_CNT, IDE_SSDE0 | IDE_PSDE0);
|
|
|
|
dm_pci_write_config16(dev, IDE_SDMA_TIM, 0x0201);
|
2014-11-15 01:18:38 +00:00
|
|
|
|
|
|
|
common_sata_init(dev, port_map);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Set Gen3 Transmitter settings if needed */
|
|
|
|
port_tx = fdtdec_get_int(blob, node, "intel,sata-port0-gen3-tx", 0);
|
|
|
|
if (port_tx)
|
2016-01-17 23:11:52 +00:00
|
|
|
pch_iobp_update(pch, SATA_IOBP_SP0G3IR, 0, port_tx);
|
2014-11-15 01:18:38 +00:00
|
|
|
|
|
|
|
port_tx = fdtdec_get_int(blob, node, "intel,sata-port1-gen3-tx", 0);
|
|
|
|
if (port_tx)
|
2016-01-17 23:11:52 +00:00
|
|
|
pch_iobp_update(pch, SATA_IOBP_SP1G3IR, 0, port_tx);
|
2014-11-15 01:18:38 +00:00
|
|
|
|
|
|
|
/* Additional Programming Requirements */
|
2016-03-16 13:44:36 +00:00
|
|
|
pch_common_sir_write(dev, 0x04, 0x00001600);
|
|
|
|
pch_common_sir_write(dev, 0x28, 0xa0000033);
|
|
|
|
reg32 = pch_common_sir_read(dev, 0x54);
|
2014-11-15 01:18:38 +00:00
|
|
|
reg32 &= 0xff000000;
|
|
|
|
reg32 |= 0x5555aa;
|
2016-03-16 13:44:36 +00:00
|
|
|
pch_common_sir_write(dev, 0x54, reg32);
|
|
|
|
pch_common_sir_write(dev, 0x64, 0xcccc8484);
|
|
|
|
reg32 = pch_common_sir_read(dev, 0x68);
|
2014-11-15 01:18:38 +00:00
|
|
|
reg32 &= 0xffff0000;
|
|
|
|
reg32 |= 0xcccc;
|
2016-03-16 13:44:36 +00:00
|
|
|
pch_common_sir_write(dev, 0x68, reg32);
|
|
|
|
reg32 = pch_common_sir_read(dev, 0x78);
|
2014-11-15 01:18:38 +00:00
|
|
|
reg32 &= 0x0000ffff;
|
|
|
|
reg32 |= 0x88880000;
|
2016-03-16 13:44:36 +00:00
|
|
|
pch_common_sir_write(dev, 0x78, reg32);
|
|
|
|
pch_common_sir_write(dev, 0x84, 0x001c7000);
|
|
|
|
pch_common_sir_write(dev, 0x88, 0x88338822);
|
|
|
|
pch_common_sir_write(dev, 0xa0, 0x001c7000);
|
|
|
|
pch_common_sir_write(dev, 0xc4, 0x0c0c0c0c);
|
|
|
|
pch_common_sir_write(dev, 0xc8, 0x0c0c0c0c);
|
|
|
|
pch_common_sir_write(dev, 0xd4, 0x10000000);
|
2014-11-15 01:18:38 +00:00
|
|
|
|
2016-01-17 23:11:52 +00:00
|
|
|
pch_iobp_update(pch, 0xea004001, 0x3fffffff, 0xc0000000);
|
|
|
|
pch_iobp_update(pch, 0xea00408a, 0xfffffcff, 0x00000100);
|
2014-11-15 01:18:38 +00:00
|
|
|
}
|
|
|
|
|
2016-01-17 23:11:38 +00:00
|
|
|
static void bd82x6x_sata_enable(struct udevice *dev)
|
2014-11-15 01:18:38 +00:00
|
|
|
{
|
2016-01-17 23:11:38 +00:00
|
|
|
const void *blob = gd->fdt_blob;
|
|
|
|
int node = dev->of_offset;
|
2014-11-15 01:18:38 +00:00
|
|
|
unsigned port_map;
|
|
|
|
const char *mode;
|
|
|
|
u16 map = 0;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Set SATA controller mode early so the resource allocator can
|
|
|
|
* properly assign IO/Memory resources for the controller.
|
|
|
|
*/
|
|
|
|
mode = fdt_getprop(blob, node, "intel,sata-mode", NULL);
|
|
|
|
if (mode && !strcmp(mode, "ahci"))
|
|
|
|
map = 0x0060;
|
|
|
|
port_map = fdtdec_get_int(blob, node, "intel,sata-port-map", 0);
|
|
|
|
|
|
|
|
map |= (port_map ^ 0x3f) << 8;
|
2016-01-17 23:11:38 +00:00
|
|
|
dm_pci_write_config16(dev, 0x90, map);
|
2014-11-15 01:18:38 +00:00
|
|
|
}
|
2016-01-17 23:11:35 +00:00
|
|
|
|
|
|
|
static int bd82x6x_sata_probe(struct udevice *dev)
|
|
|
|
{
|
2016-01-17 23:11:52 +00:00
|
|
|
struct udevice *pch;
|
|
|
|
int ret;
|
|
|
|
|
2016-02-11 20:23:26 +00:00
|
|
|
ret = uclass_first_device_err(UCLASS_PCH, &pch);
|
2016-01-17 23:11:52 +00:00
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
2016-01-17 23:11:35 +00:00
|
|
|
if (!(gd->flags & GD_FLG_RELOC))
|
2016-01-17 23:11:38 +00:00
|
|
|
bd82x6x_sata_enable(dev);
|
2016-01-17 23:11:37 +00:00
|
|
|
else
|
2016-01-17 23:11:52 +00:00
|
|
|
bd82x6x_sata_init(dev, pch);
|
2016-01-17 23:11:35 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct udevice_id bd82x6x_ahci_ids[] = {
|
|
|
|
{ .compatible = "intel,pantherpoint-ahci" },
|
|
|
|
{ }
|
|
|
|
};
|
|
|
|
|
|
|
|
U_BOOT_DRIVER(ahci_ivybridge_drv) = {
|
|
|
|
.name = "ahci_ivybridge",
|
2016-05-01 17:35:52 +00:00
|
|
|
.id = UCLASS_AHCI,
|
2016-01-17 23:11:35 +00:00
|
|
|
.of_match = bd82x6x_ahci_ids,
|
|
|
|
.probe = bd82x6x_sata_probe,
|
|
|
|
};
|