Factor out a few commonly duplicated functions from northbridge.c.
[coreboot.git] / src / southbridge / intel / i82801bx / i82801bx_sata.c
1 /*
2  * This file is part of the coreboot project.
3  *
4  * Copyright (C) 2005 Tyan Computer
5  * (Written by Yinghai Lu <yinghailu@gmail.com> for Tyan Computer)
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
20  */
21
22 #include <console/console.h>
23 #include <device/device.h>
24 #include <device/pci.h>
25 #include <device/pci_ids.h>
26 #include "i82801bx.h"
27
28 /* TODO: Set dynamically, if the user only wants one SATA channel or none
29  * at all.
30  */
31 static void sata_init(struct device *dev)
32 {
33         /* SATA configuration */
34         pci_write_config8(dev, 0x04, 0x07);
35         pci_write_config8(dev, 0x09, 0x8f);
36
37         /* Set timmings */
38         pci_write_config16(dev, 0x40, 0x0a307);
39         pci_write_config16(dev, 0x42, 0x0a307);
40
41         /* Sync DMA */
42         pci_write_config16(dev, 0x48, 0x000f);
43         pci_write_config16(dev, 0x4a, 0x1111);
44
45         /* 66 MHz */
46         pci_write_config16(dev, 0x54, 0xf00f);
47
48         /* Combine IDE - SATA configuration */
49         pci_write_config8(dev, 0x90, 0x0);
50
51         /* Port 0 & 1 enable */
52         pci_write_config8(dev, 0x92, 0x33);
53
54         /* Initialize SATA. */
55         pci_write_config16(dev, 0xa0, 0x0018);
56         pci_write_config32(dev, 0xa4, 0x00000264);
57         pci_write_config16(dev, 0xa0, 0x0040);
58         pci_write_config32(dev, 0xa4, 0x00220043);
59 }
60
61 static struct device_operations sata_ops = {
62         .read_resources         = pci_dev_read_resources,
63         .set_resources          = pci_dev_set_resources,
64         .enable_resources       = pci_dev_enable_resources,
65         .init                   = sata_init,
66         .scan_bus               = 0,
67         .enable                 = i82801bx_enable,
68 };
69
70 /* 82801EB */
71 static const struct pci_driver i82801eb_sata_driver __pci_driver = {
72         .ops    = &sata_ops,
73         .vendor = PCI_VENDOR_ID_INTEL,
74         .device = 0x24d1,
75 };
76
77 /* 82801ER */
78 static const struct pci_driver i82801er_sata_driver __pci_driver = {
79         .ops    = &sata_ops,
80         .vendor = PCI_VENDOR_ID_INTEL,
81         .device = 0x24df,
82 };