2 * Copyright 2004 Tyan Computer
5 #include <console/console.h>
6 #include <device/device.h>
8 #include <device/pci.h>
9 #include <device/pci_ids.h>
10 #include <device/pci_ops.h>
14 static void sata_com_reset(struct device *dev, unsigned reset)
22 base = (uint32_t *) pci_read_config32(dev, 0x24);
24 printk_debug("base = %08x\r\n", base);
27 *(base + 4) = 0xffffffff;
28 *(base + 0x44) = 0xffffffff;
36 *(base + 0x48) = dword;
42 *(base + 0x48) = dword;
50 printk_debug("*(base+0)=%08x\r\n",dword);
55 if((dword & 0x10000)!=0) break;
58 printk_debug("loop=%d, *(base+4)=%08x\r\n",loop, dword);
62 dword = *(base+ 0x40);
63 printk_debug("*(base+0x40)=%08x\r\n",dword);
67 dword = *(base + 0x44);
68 if((dword & 0x10000)!=0) break;
71 printk_debug("loop=%d, *(base+0x44)=%08x\r\n",loop, dword);
77 static void sata_init(struct device *dev)
82 struct southbridge_nvidia_ck804_config *conf;
83 conf = dev->chip_info;
85 dword = pci_read_config32(dev, 0x50);
86 /* Ensure prefetch is disabled */
87 dword &= ~((1 << 15) | (1 << 13));
88 if (conf->sata1_enable) {
89 /* Enable secondary SATA interface */
91 printk_debug("SATA S \t");
93 if (conf->sata0_enable) {
94 /* Enable primary SATA interface */
96 printk_debug("SATA P \n");
111 //DO NOT relay OK and PAGE_FRNDLY_DTXFR_CNT.
112 dword &= ~(0x1f<<24);
115 pci_write_config32(dev, 0x50, dword);
119 dword = pci_read_config32(dev, 0x7c);
121 pci_write_config32(dev, 0x7c, dword);
123 dword = pci_read_config32(dev, 0xd0);
124 dword &= ~(0xff<<24);
126 pci_write_config32(dev, 0xd0, dword);
128 dword = pci_read_config32(dev, 0xe0);
129 dword &= ~(0xff<<24);
131 pci_write_config32(dev, 0xe0, dword);
134 dword = pci_read_config32(dev, 0xf8);
136 pci_write_config32(dev, 0xf8, dword);
139 dword = pci_read_config32(dev, 0xac);
140 dword &= ~((1<<13)|(1<<14));
141 dword |= (1<<13)|(0<<14);
142 pci_write_config32(dev, 0xac, dword);
144 sata_com_reset(dev, 1); // for discover some s-atapi device
149 static void lpci_set_subsystem(device_t dev, unsigned vendor, unsigned device)
151 pci_write_config32(dev, 0x40,
152 ((device & 0xffff) << 16) | (vendor & 0xffff));
154 static struct pci_operations lops_pci = {
155 .set_subsystem = lpci_set_subsystem,
158 static struct device_operations sata_ops = {
159 .read_resources = pci_dev_read_resources,
160 .set_resources = pci_dev_set_resources,
161 .enable_resources = pci_dev_enable_resources,
162 // .enable = ck804_enable,
165 .ops_pci = &lops_pci,
168 static const struct pci_driver sata0_driver __pci_driver = {
170 .vendor = PCI_VENDOR_ID_NVIDIA,
171 .device = PCI_DEVICE_ID_NVIDIA_CK804_SATA0,
174 static const struct pci_driver sata1_driver __pci_driver = {
176 .vendor = PCI_VENDOR_ID_NVIDIA,
177 .device = PCI_DEVICE_ID_NVIDIA_CK804_SATA1,