90dd2bf48d31945dbc8ba2368cbcf622885fb2e5
[coreboot.git] / src / southbridge / nvidia / mcp55 / ide.c
1 /*
2  * This file is part of the coreboot project.
3  *
4  * Copyright (C) 2004 Tyan Computer
5  * Written by Yinghai Lu <yhlu@tyan.com> for Tyan Computer.
6  * Copyright (C) 2006,2007 AMD
7  * Written by Yinghai Lu <yinghai.lu@amd.com> for AMD.
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
22  */
23
24 #include <console/console.h>
25 #include <device/device.h>
26 #include <device/pci.h>
27 #include <device/pci_ids.h>
28 #include <device/pci_ops.h>
29 #include "mcp55.h"
30
31 static void ide_init(struct device *dev)
32 {
33         struct southbridge_nvidia_mcp55_config *conf;
34         /* Enable ide devices so the linux ide driver will work */
35         uint32_t dword;
36         uint16_t word;
37         uint8_t byte;
38         conf = dev->chip_info;
39
40         word = pci_read_config16(dev, 0x50);
41         /* Ensure prefetch is disabled */
42         word &= ~((1 << 15) | (1 << 13));
43         if (conf->ide1_enable) {
44                 /* Enable secondary ide interface */
45                 word |= (1<<0);
46                 printk(BIOS_DEBUG, "IDE1 \t");
47         }
48         if (conf->ide0_enable) {
49                 /* Enable primary ide interface */
50                 word |= (1<<1);
51                 printk(BIOS_DEBUG, "IDE0\n");
52         }
53
54         word |= (1<<12);
55         word |= (1<<14);
56
57         pci_write_config16(dev, 0x50, word);
58
59
60         byte = 0x20 ; // Latency: 64-->32
61         pci_write_config8(dev, 0xd, byte);
62
63         dword = pci_read_config32(dev, 0xf8);
64         dword |= 12;
65         pci_write_config32(dev, 0xf8, dword);
66 #if CONFIG_PCI_ROM_RUN == 1
67         pci_dev_init(dev);
68 #endif
69
70 }
71
72 static struct device_operations ide_ops  = {
73         .read_resources = pci_dev_read_resources,
74         .set_resources  = pci_dev_set_resources,
75         .enable_resources       = pci_dev_enable_resources,
76         .init           = ide_init,
77         .scan_bus       = 0,
78 //      .enable         = mcp55_enable,
79         .ops_pci        = &mcp55_pci_ops,
80 };
81
82 static const struct pci_driver ide_driver __pci_driver = {
83         .ops    = &ide_ops,
84         .vendor = PCI_VENDOR_ID_NVIDIA,
85         .device = PCI_DEVICE_ID_NVIDIA_MCP55_IDE,
86 };
87