Since some people disapprove of white space cleanups mixed in regular commits
[coreboot.git] / src / southbridge / intel / i3100 / i3100_sata.c
1 /*
2  * This file is part of the coreboot project.
3  *
4  * Copyright (C) 2008 Arastra, 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 version 2 as
8  * published by the Free Software Foundation.
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
21 /* This code is based on src/southbridge/intel/esb6300/esb6300_sata.c */
22
23 #include <console/console.h>
24 #include <device/device.h>
25 #include <device/pci.h>
26 #include <device/pci_ids.h>
27 #include <device/pci_ops.h>
28 #include "i3100.h"
29
30 #define SATA_CMD     0x04
31 #define SATA_PI      0x09
32 #define SATA_PTIM    0x40
33 #define SATA_STIM    0x42
34 #define SATA_D1TIM   0x44
35 #define SATA_SYNCC   0x48
36 #define SATA_SYNCTIM 0x4A
37 #define SATA_IIOC    0x54
38 #define SATA_MAP     0x90
39 #define SATA_PCS     0x91
40 #define SATA_ACR0    0xA8
41 #define SATA_ACR1    0xAC
42 #define SATA_ATC     0xC0
43 #define SATA_ATS     0xC4
44 #define SATA_SP      0xD0
45
46 typedef struct southbridge_intel_i3100_config config_t;
47
48 static void sata_init(struct device *dev)
49 {
50         u8 ahci;
51
52         /* Get the chip configuration */
53         ahci = (pci_read_config8(dev, SATA_MAP) >> 6) & 0x03;
54
55         /* Enable SATA devices */
56         printk(BIOS_INFO, "SATA init (%s mode)\n", ahci ? "AHCI" : "Legacy");
57
58         if(ahci) {
59           /* AHCI mode */
60           pci_write_config8(dev, SATA_MAP, (1 << 6) | (0 << 0));
61
62           /* Enable ports */
63           pci_write_config8(dev, SATA_PCS, 0x03);
64           pci_write_config8(dev, SATA_PCS + 1, 0x0F);
65
66           /* Setup timings */
67           pci_write_config16(dev, SATA_PTIM, 0x8000);
68           pci_write_config16(dev, SATA_STIM, 0x8000);
69
70           /* Synchronous DMA */
71           pci_write_config8(dev, SATA_SYNCC, 0);
72           pci_write_config16(dev, SATA_SYNCTIM, 0);
73
74           /* IDE I/O configuration */
75           pci_write_config32(dev, SATA_IIOC, 0);
76
77         } else {
78           /* SATA configuration */
79           pci_write_config8(dev, SATA_CMD, 0x07);
80           pci_write_config8(dev, SATA_PI, 0x8f);
81
82           /* Set timings */
83           pci_write_config16(dev, SATA_PTIM, 0x0a307);
84           pci_write_config16(dev, SATA_STIM, 0x0a307);
85
86           /* Sync DMA */
87           pci_write_config8(dev, SATA_SYNCC, 0x0f);
88           pci_write_config16(dev, SATA_SYNCTIM, 0x1111);
89
90           /* Fast ATA */
91           pci_write_config16(dev, SATA_IIOC, 0x1000);
92
93           /* Select IDE mode */
94           pci_write_config8(dev, SATA_MAP, 0x00);
95
96           /* Enable ports 0-3 */
97           pci_write_config8(dev, SATA_PCS + 1, 0x0f);
98
99         }
100         printk(BIOS_DEBUG, "SATA Enabled\n");
101 }
102
103 static void sata_set_subsystem(device_t dev, unsigned vendor, unsigned device)
104 {
105         pci_write_config32(dev, PCI_SUBSYSTEM_VENDOR_ID,
106                 ((device & 0xffff) << 16) | (vendor & 0xffff));
107 }
108
109 static struct pci_operations lops_pci = {
110         .set_subsystem = sata_set_subsystem,
111 };
112
113 static struct device_operations sata_ops  = {
114         .read_resources   = pci_dev_read_resources,
115         .set_resources    = pci_dev_set_resources,
116         .enable_resources = pci_dev_enable_resources,
117         .init             = sata_init,
118         .scan_bus         = 0,
119         .enable           = i3100_enable,
120         .ops_pci          = &lops_pci,
121 };
122
123 static const struct pci_driver ide_driver __pci_driver = {
124         .ops    = &sata_ops,
125         .vendor = PCI_VENDOR_ID_INTEL,
126         .device = PCI_DEVICE_ID_INTEL_3100_IDE,
127 };
128
129 static const struct pci_driver sata_driver __pci_driver = {
130         .ops    = &sata_ops,
131         .vendor = PCI_VENDOR_ID_INTEL,
132         .device = PCI_DEVICE_ID_INTEL_3100_AHCI,
133 };
134
135 static const struct pci_driver ide_driver_ep80579 __pci_driver = {
136         .ops    = &sata_ops,
137         .vendor = PCI_VENDOR_ID_INTEL,
138         .device = PCI_DEVICE_ID_INTEL_EP80579_IDE,
139 };
140
141 static const struct pci_driver sata_driver_ep80579 __pci_driver = {
142         .ops    = &sata_ops,
143         .vendor = PCI_VENDOR_ID_INTEL,
144         .device = PCI_DEVICE_ID_INTEL_EP80579_AHCI,
145 };