2005-07-06 19:13:46 +02:00
|
|
|
/*
|
|
|
|
* Copyright 2004 Tyan Computer
|
|
|
|
* by yhlu@tyan.com
|
|
|
|
*/
|
2008-10-02 20:19:17 +02:00
|
|
|
|
2005-07-06 19:13:46 +02:00
|
|
|
#include <console/console.h>
|
|
|
|
#include <device/device.h>
|
|
|
|
#include <delay.h>
|
|
|
|
#include <device/pci.h>
|
|
|
|
#include <device/pci_ids.h>
|
|
|
|
#include <device/pci_ops.h>
|
|
|
|
#include "ck804.h"
|
|
|
|
|
2009-05-01 00:45:41 +02:00
|
|
|
#ifndef CK804_SATA_RESET_FOR_ATAPI
|
|
|
|
#define CK804_SATA_RESET_FOR_ATAPI 0
|
|
|
|
#endif
|
|
|
|
|
2009-02-09 18:52:54 +01:00
|
|
|
#if CK804_SATA_RESET_FOR_ATAPI
|
2005-07-06 19:13:46 +02:00
|
|
|
static void sata_com_reset(struct device *dev, unsigned reset)
|
|
|
|
// reset = 1 : reset
|
|
|
|
// reset = 0 : clear
|
|
|
|
{
|
2008-09-18 18:27:00 +02:00
|
|
|
uint32_t *base;
|
2005-07-06 19:13:46 +02:00
|
|
|
uint32_t dword;
|
|
|
|
int loop;
|
|
|
|
|
2008-09-18 18:27:00 +02:00
|
|
|
base = (uint32_t *) pci_read_config32(dev, 0x24);
|
2005-07-06 19:13:46 +02:00
|
|
|
|
2009-02-09 18:52:54 +01:00
|
|
|
printk_debug("base = %08lx\n", base);
|
2005-07-06 19:13:46 +02:00
|
|
|
|
2008-10-02 20:19:17 +02:00
|
|
|
if (reset) {
|
|
|
|
*(base + 4) = 0xffffffff;
|
|
|
|
*(base + 0x44) = 0xffffffff;
|
2008-09-18 18:27:00 +02:00
|
|
|
}
|
2005-07-06 19:13:46 +02:00
|
|
|
|
2008-10-02 20:19:17 +02:00
|
|
|
dword = *(base + 8);
|
2008-09-18 18:27:00 +02:00
|
|
|
dword &= ~(0xf);
|
|
|
|
dword |= reset;
|
2005-07-06 19:13:46 +02:00
|
|
|
|
2008-09-18 18:27:00 +02:00
|
|
|
*(base + 8) = dword;
|
|
|
|
*(base + 0x48) = dword;
|
2005-07-06 19:13:46 +02:00
|
|
|
|
|
|
|
#if 0
|
|
|
|
udelay(1000);
|
|
|
|
dword &= ~(0xf);
|
2008-09-18 18:27:00 +02:00
|
|
|
*(base + 8) = dword;
|
|
|
|
*(base + 0x48) = dword;
|
2005-07-06 19:13:46 +02:00
|
|
|
#endif
|
|
|
|
|
2008-10-02 20:19:17 +02:00
|
|
|
if (reset)
|
|
|
|
return;
|
2005-07-06 19:13:46 +02:00
|
|
|
|
2008-10-02 20:19:17 +02:00
|
|
|
dword = *(base + 0);
|
|
|
|
printk_debug("*(base+0)=%08x\r\n", dword);
|
|
|
|
if (dword == 0x113) {
|
|
|
|
loop = 200000; // 2
|
2005-07-06 19:13:46 +02:00
|
|
|
do {
|
2008-10-02 20:19:17 +02:00
|
|
|
dword = *(base + 4);
|
|
|
|
if ((dword & 0x10000) != 0)
|
|
|
|
break;
|
2005-07-06 19:13:46 +02:00
|
|
|
udelay(10);
|
2008-10-02 20:19:17 +02:00
|
|
|
} while (--loop > 0);
|
|
|
|
printk_debug("loop=%d, *(base+4)=%08x\r\n", loop, dword);
|
2005-07-06 19:13:46 +02:00
|
|
|
}
|
|
|
|
|
2008-10-02 20:19:17 +02:00
|
|
|
dword = *(base + 0x40);
|
|
|
|
printk_debug("*(base+0x40)=%08x\r\n", dword);
|
|
|
|
if (dword == 0x113) {
|
|
|
|
loop = 200000; //2
|
|
|
|
do {
|
|
|
|
dword = *(base + 0x44);
|
|
|
|
if ((dword & 0x10000) != 0)
|
|
|
|
break;
|
2005-07-06 19:13:46 +02:00
|
|
|
udelay(10);
|
2008-10-02 20:19:17 +02:00
|
|
|
} while (--loop > 0);
|
|
|
|
printk_debug("loop=%d, *(base+0x44)=%08x\r\n", loop, dword);
|
2005-07-06 19:13:46 +02:00
|
|
|
}
|
|
|
|
}
|
2009-02-09 18:52:54 +01:00
|
|
|
#endif
|
2005-07-06 19:13:46 +02:00
|
|
|
|
|
|
|
static void sata_init(struct device *dev)
|
|
|
|
{
|
2008-09-18 18:27:00 +02:00
|
|
|
uint32_t dword;
|
2005-07-06 19:13:46 +02:00
|
|
|
struct southbridge_nvidia_ck804_config *conf;
|
2008-10-02 20:19:17 +02:00
|
|
|
|
2005-07-06 19:13:46 +02:00
|
|
|
conf = dev->chip_info;
|
|
|
|
|
2008-09-18 18:27:00 +02:00
|
|
|
dword = pci_read_config32(dev, 0x50);
|
2008-10-02 20:19:17 +02:00
|
|
|
/* Ensure prefetch is disabled. */
|
2008-09-18 18:27:00 +02:00
|
|
|
dword &= ~((1 << 15) | (1 << 13));
|
|
|
|
if (conf->sata1_enable) {
|
2008-10-02 20:19:17 +02:00
|
|
|
/* Enable secondary SATA interface. */
|
|
|
|
dword |= (1 << 0);
|
|
|
|
printk_debug("SATA S \t");
|
2008-09-18 18:27:00 +02:00
|
|
|
}
|
|
|
|
if (conf->sata0_enable) {
|
2008-10-02 20:19:17 +02:00
|
|
|
/* Enable primary SATA interface. */
|
|
|
|
dword |= (1 << 1);
|
|
|
|
printk_debug("SATA P \n");
|
2008-09-18 18:27:00 +02:00
|
|
|
}
|
2005-10-01 09:32:04 +02:00
|
|
|
#if 0
|
2008-10-02 20:19:17 +02:00
|
|
|
/* Write back */
|
|
|
|
dword |= (1 << 12);
|
|
|
|
dword |= (1 << 14);
|
2005-10-01 09:32:04 +02:00
|
|
|
#endif
|
2005-07-06 19:13:46 +02:00
|
|
|
|
2005-10-01 09:32:04 +02:00
|
|
|
#if 0
|
2008-10-02 20:19:17 +02:00
|
|
|
/* ADMA */
|
|
|
|
dword |= (1 << 16);
|
|
|
|
dword |= (1 << 17);
|
2005-07-06 19:13:46 +02:00
|
|
|
#endif
|
|
|
|
|
2008-09-18 18:27:00 +02:00
|
|
|
#if 1
|
2008-10-02 20:19:17 +02:00
|
|
|
/* DO NOT relay OK and PAGE_FRNDLY_DTXFR_CNT. */
|
|
|
|
dword &= ~(0x1f << 24);
|
|
|
|
dword |= (0x15 << 24);
|
2005-07-06 19:13:46 +02:00
|
|
|
#endif
|
2008-09-18 18:27:00 +02:00
|
|
|
pci_write_config32(dev, 0x50, dword);
|
2005-07-06 19:13:46 +02:00
|
|
|
|
2005-10-01 09:32:04 +02:00
|
|
|
#if 0
|
2008-10-02 20:19:17 +02:00
|
|
|
/* SLUMBER_DURING_D3 */
|
2008-09-18 18:27:00 +02:00
|
|
|
dword = pci_read_config32(dev, 0x7c);
|
2008-10-02 20:19:17 +02:00
|
|
|
dword &= ~(1 << 4);
|
2008-09-18 18:27:00 +02:00
|
|
|
pci_write_config32(dev, 0x7c, dword);
|
2005-07-06 19:13:46 +02:00
|
|
|
|
|
|
|
dword = pci_read_config32(dev, 0xd0);
|
2008-10-02 20:19:17 +02:00
|
|
|
dword &= ~(0xff << 24);
|
|
|
|
dword |= (0x68 << 24);
|
2005-07-06 19:13:46 +02:00
|
|
|
pci_write_config32(dev, 0xd0, dword);
|
|
|
|
|
2008-09-18 18:27:00 +02:00
|
|
|
dword = pci_read_config32(dev, 0xe0);
|
2008-10-02 20:19:17 +02:00
|
|
|
dword &= ~(0xff << 24);
|
|
|
|
dword |= (0x68 << 24);
|
2005-07-06 19:13:46 +02:00
|
|
|
pci_write_config32(dev, 0xe0, dword);
|
|
|
|
#endif
|
|
|
|
|
2008-09-18 18:27:00 +02:00
|
|
|
dword = pci_read_config32(dev, 0xf8);
|
|
|
|
dword |= 2;
|
|
|
|
pci_write_config32(dev, 0xf8, dword);
|
2005-07-06 19:13:46 +02:00
|
|
|
|
2009-02-09 18:52:54 +01:00
|
|
|
#if CK804_SATA_RESET_FOR_ATAPI
|
2005-07-06 19:13:46 +02:00
|
|
|
dword = pci_read_config32(dev, 0xac);
|
2008-10-02 20:19:17 +02:00
|
|
|
dword &= ~((1 << 13) | (1 << 14));
|
|
|
|
dword |= (1 << 13) | (0 << 14);
|
2005-07-06 19:13:46 +02:00
|
|
|
pci_write_config32(dev, 0xac, dword);
|
|
|
|
|
2008-10-02 20:19:17 +02:00
|
|
|
sata_com_reset(dev, 1); /* For discover some s-atapi device. */
|
2005-07-06 19:13:46 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
static void lpci_set_subsystem(device_t dev, unsigned vendor, unsigned device)
|
|
|
|
{
|
2008-09-18 18:27:00 +02:00
|
|
|
pci_write_config32(dev, 0x40,
|
2008-10-02 20:19:17 +02:00
|
|
|
((device & 0xffff) << 16) | (vendor & 0xffff));
|
2005-07-06 19:13:46 +02:00
|
|
|
}
|
2008-10-02 20:19:17 +02:00
|
|
|
|
2005-07-06 19:13:46 +02:00
|
|
|
static struct pci_operations lops_pci = {
|
2008-09-18 18:27:00 +02:00
|
|
|
.set_subsystem = lpci_set_subsystem,
|
2005-07-06 19:13:46 +02:00
|
|
|
};
|
|
|
|
|
2008-10-02 20:19:17 +02:00
|
|
|
static struct device_operations sata_ops = {
|
2005-07-06 19:13:46 +02:00
|
|
|
.read_resources = pci_dev_read_resources,
|
|
|
|
.set_resources = pci_dev_set_resources,
|
|
|
|
.enable_resources = pci_dev_enable_resources,
|
2008-10-02 20:19:17 +02:00
|
|
|
// .enable = ck804_enable,
|
2005-07-06 19:13:46 +02:00
|
|
|
.init = sata_init,
|
|
|
|
.scan_bus = 0,
|
|
|
|
.ops_pci = &lops_pci,
|
|
|
|
};
|
|
|
|
|
2007-10-24 11:08:58 +02:00
|
|
|
static const struct pci_driver sata0_driver __pci_driver = {
|
2005-07-06 19:13:46 +02:00
|
|
|
.ops = &sata_ops,
|
|
|
|
.vendor = PCI_VENDOR_ID_NVIDIA,
|
|
|
|
.device = PCI_DEVICE_ID_NVIDIA_CK804_SATA0,
|
|
|
|
};
|
|
|
|
|
2007-10-24 11:08:58 +02:00
|
|
|
static const struct pci_driver sata1_driver __pci_driver = {
|
2008-09-18 18:27:00 +02:00
|
|
|
.ops = &sata_ops,
|
|
|
|
.vendor = PCI_VENDOR_ID_NVIDIA,
|
|
|
|
.device = PCI_DEVICE_ID_NVIDIA_CK804_SATA1,
|
2005-07-06 19:13:46 +02:00
|
|
|
};
|