2 * This file is part of the coreboot project.
4 * Copyright (C) 2008 Arastra, Inc.
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.
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.
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
21 /* This code is based on src/southbridge/intel/esb6300/esb6300_sata.c */
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>
30 typedef struct southbridge_intel_i3100_config config_t;
32 static void sata_init(struct device *dev)
36 config_t *config = dev->chip_info;
39 printk(BIOS_ERR, "i3100_sata: error: device not in devicetree.cb!\n");
43 /* Get the chip configuration */
44 ahci = (pci_read_config8(dev, SATA_MAP) >> 6) & 0x03;
46 /* Enable SATA devices */
47 printk(BIOS_INFO, "SATA init (%s mode)\n", ahci ? "AHCI" : "Legacy");
51 pci_write_config8(dev, SATA_MAP, (1 << 6) | (0 << 0));
54 pci_write_config8(dev, SATA_PCS, 0x03);
55 pci_write_config8(dev, SATA_PCS + 1, 0x0F);
58 pci_write_config16(dev, SATA_PTIM, 0x8000);
59 pci_write_config16(dev, SATA_STIM, 0x8000);
62 pci_write_config8(dev, SATA_SYNCC, 0);
63 pci_write_config16(dev, SATA_SYNCTIM, 0);
65 /* IDE I/O configuration */
66 pci_write_config32(dev, SATA_IIOC, 0);
68 ahci_bar = (u32 *)(pci_read_config32(dev, 0x27) & ~0x3ff);
69 ahci_bar[3] = config->sata_ports_implemented;
71 /* SATA configuration */
72 pci_write_config8(dev, SATA_CMD, 0x07);
73 pci_write_config8(dev, SATA_PI, 0x8f);
76 pci_write_config16(dev, SATA_PTIM, 0x0a307);
77 pci_write_config16(dev, SATA_STIM, 0x0a307);
80 pci_write_config8(dev, SATA_SYNCC, 0x0f);
81 pci_write_config16(dev, SATA_SYNCTIM, 0x1111);
84 pci_write_config16(dev, SATA_IIOC, 0x1000);
87 pci_write_config8(dev, SATA_MAP, 0x00);
89 /* Enable ports 0-3 */
90 pci_write_config8(dev, SATA_PCS + 1, 0x0f);
94 /* secret init sequence, required */
95 pci_write_config32(dev, 0x94, 0x00400180);
96 pci_write_config32(dev, 0xa0, 0x18);
97 pci_write_config32(dev, 0xa4, 0x224);
98 pci_write_config32(dev, 0xa0, 0x42);
99 pci_write_config32(dev, 0xa4, 0x22006d);
100 pci_write_config32(dev, 0xa0, 0x84);
101 pci_write_config32(dev, 0xa4, 0x24);
102 pci_write_config32(dev, 0xa0, 0x7a);
103 pci_write_config32(dev, 0xa4, 0x220000);
104 pci_write_config32(dev, 0xa0, 0x9c);
105 pci_write_config32(dev, 0xa4, 0x24);
106 pci_write_config32(dev, 0xa0, 0x90);
107 pci_write_config32(dev, 0xa4, 0x220000);
108 pci_write_config32(dev, 0xa0, 0xa0);
109 pci_write_config32(dev, 0xa4, 0x12492aa);
111 printk(BIOS_DEBUG, "SATA Enabled\n");
114 static void sata_set_subsystem(device_t dev, unsigned vendor, unsigned device)
116 pci_write_config32(dev, PCI_SUBSYSTEM_VENDOR_ID,
117 ((device & 0xffff) << 16) | (vendor & 0xffff));
120 static struct pci_operations lops_pci = {
121 .set_subsystem = sata_set_subsystem,
124 static struct device_operations sata_ops = {
125 .read_resources = pci_dev_read_resources,
126 .set_resources = pci_dev_set_resources,
127 .enable_resources = pci_dev_enable_resources,
130 .enable = i3100_enable,
131 .ops_pci = &lops_pci,
134 static const struct pci_driver ide_driver __pci_driver = {
136 .vendor = PCI_VENDOR_ID_INTEL,
137 .device = PCI_DEVICE_ID_INTEL_3100_IDE,
140 static const struct pci_driver sata_driver __pci_driver = {
142 .vendor = PCI_VENDOR_ID_INTEL,
143 .device = PCI_DEVICE_ID_INTEL_3100_AHCI,
146 static const struct pci_driver ide_driver_ep80579 __pci_driver = {
148 .vendor = PCI_VENDOR_ID_INTEL,
149 .device = PCI_DEVICE_ID_INTEL_EP80579_IDE,
152 static const struct pci_driver sata_driver_ep80579 __pci_driver = {
154 .vendor = PCI_VENDOR_ID_INTEL,
155 .device = PCI_DEVICE_ID_INTEL_EP80579_AHCI,