f46a057ef734779a4ee96c084bf29ab7d6c1d5a0
[coreboot.git] / src / southbridge / nvidia / ck804 / ck804_ide.c
1 /*
2  * Copyright 2004 Tyan Computer
3  *  by yhlu@tyan.com
4  */
5
6 #include <console/console.h>
7 #include <device/device.h>
8 #include <device/pci.h>
9 #include <device/pci_ids.h>
10 #include <device/pci_ops.h>
11 #include "ck804.h"
12
13 static void ide_init(struct device *dev)
14 {
15         struct southbridge_nvidia_ck804_config *conf;
16         uint32_t dword;
17         uint16_t word;
18         uint8_t byte;
19
20         conf = dev->chip_info;
21
22         word = pci_read_config16(dev, 0x50);
23         /* Ensure prefetch is disabled. */
24         word &= ~((1 << 15) | (1 << 13));
25         if (conf->ide1_enable) {
26                 /* Enable secondary IDE interface. */
27                 word |= (1 << 0);
28                 printk(BIOS_DEBUG, "IDE1 \t");
29         }
30         if (conf->ide0_enable) {
31                 /* Enable primary IDE interface. */
32                 word |= (1 << 1);
33                 printk(BIOS_DEBUG, "IDE0\n");
34         }
35
36         word |= (1 << 12);
37         word |= (1 << 14);
38
39         pci_write_config16(dev, 0x50, word);
40
41         byte = 0x20;            /* Latency: 64 --> 32 */
42         pci_write_config8(dev, 0xd, byte);
43
44         dword = pci_read_config32(dev, 0xf8);
45         dword |= 12;
46         pci_write_config32(dev, 0xf8, dword);
47
48 #if CONFIG_PCI_ROM_RUN == 1
49         pci_dev_init(dev);
50 #endif
51 }
52
53 static void lpci_set_subsystem(device_t dev, unsigned vendor, unsigned device)
54 {
55         pci_write_config32(dev, 0x40,
56                            ((device & 0xffff) << 16) | (vendor & 0xffff));
57 }
58
59 static struct pci_operations lops_pci = {
60         .set_subsystem = lpci_set_subsystem,
61 };
62
63 static struct device_operations ide_ops = {
64         .read_resources   = pci_dev_read_resources,
65         .set_resources    = pci_dev_set_resources,
66         .enable_resources = pci_dev_enable_resources,
67         .init             = ide_init,
68         .scan_bus         = 0,
69         // .enable        = ck804_enable,
70         .ops_pci          = &lops_pci,
71 };
72
73 static const struct pci_driver ide_driver __pci_driver = {
74         .ops    = &ide_ops,
75         .vendor = PCI_VENDOR_ID_NVIDIA,
76         .device = PCI_DEVICE_ID_NVIDIA_CK804_IDE,
77 };