4652ca2539ec6ff9cbe9cf24e1d5f15ce0e4825f
[coreboot.git] / src / southbridge / amd / sb700 / ide.c
1 /*
2  * This file is part of the coreboot project.
3  *
4  * Copyright (C) 2010 Advanced Micro Devices, Inc.
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; version 2 of the License.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
18  */
19
20 #include <console/console.h>
21 #include <device/device.h>
22 #include <device/pci.h>
23 #include <device/pci_ids.h>
24 #include <device/pci_ops.h>
25 #include "sb700.h"
26
27 static void ide_init(struct device *dev)
28 {
29         struct southbridge_amd_sb700_config *conf;
30         /* Enable ide devices so the linux ide driver will work */
31         u32 dword;
32         u8 byte;
33
34         conf = dev->chip_info;
35
36         /* RPR9.1 disable MSI */
37         /* TODO: For A14, it should set as 1. I doubt it. */
38         dword = pci_read_config32(dev, 0x70);
39         dword &= ~(1 << 16);
40         pci_write_config32(dev, 0x70, dword);
41
42         /* Enable UDMA on all devices, it will become UDMA0 (default PIO is PIO0) */
43         byte = pci_read_config8(dev, 0x54);
44         byte |= 0xf;
45         pci_write_config8(dev, 0x54, byte);
46
47         /* Enable I/O Access&& Bus Master */
48         dword = pci_read_config16(dev, 0x4);
49         dword |= 1 << 2;
50         pci_write_config16(dev, 0x4, dword);
51
52         /* set ide as primary, if you want to boot from IDE, you'd better set it
53          * in $vendor/$mainboard/devicetree.cb */
54          
55         
56         if (conf->boot_switch_sata_ide == 1) {
57                 struct device *sm_dev = dev_find_slot(0, PCI_DEVFN(0x14, 0));
58                 byte = pci_read_config8(sm_dev, 0xAD);
59                 byte |= 1 << 4;
60                 pci_write_config8(sm_dev, 0xAD, byte);
61         }
62
63 #if CONFIG_PCI_ROM_RUN == 1
64         pci_dev_init(dev);
65 #endif
66 }
67
68 static struct pci_operations lops_pci = {
69         .set_subsystem = pci_dev_set_subsystem,
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         .ops_pci = &lops_pci,
79 };
80
81 static const struct pci_driver ide_driver __pci_driver = {
82         .ops = &ide_ops,
83         .vendor = PCI_VENDOR_ID_ATI,
84         .device = PCI_DEVICE_ID_ATI_SB700_IDE,
85 };