blob: 97092726fa241c7fd92d2eff16ed35a1e1c0abf3 [file] [log] [blame]
Stefan Reinauerdebb11f2008-10-29 04:46:52 +00001/*
2 * This file is part of the coreboot project.
3 *
Stefan Reinauera8e11682009-03-11 14:54:18 +00004 * Copyright (C) 2008-2009 coresystems GmbH
Stefan Reinauerdebb11f2008-10-29 04:46:52 +00005 *
Stefan Reinauera8e11682009-03-11 14:54:18 +00006 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License as
8 * published by the Free Software Foundation; version 2 of
9 * the License.
Stefan Reinauerdebb11f2008-10-29 04:46:52 +000010 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
Stefan Reinauerdebb11f2008-10-29 04:46:52 +000015 */
16
17#include <console/console.h>
18#include <device/device.h>
19#include <device/pci.h>
20#include <device/pci_ids.h>
21#include "i82801gx.h"
22
23typedef struct southbridge_intel_i82801gx_config config_t;
24
25static void ide_init(struct device *dev)
26{
27 u16 ideTimingConfig;
28 u32 reg32;
Stefan Reinauera8e11682009-03-11 14:54:18 +000029 u32 enable_primary, enable_secondary;
Stefan Reinauerdebb11f2008-10-29 04:46:52 +000030
31 /* Get the chip configuration */
32 config_t *config = dev->chip_info;
33
Paul Menzel7f1df8c2015-10-11 15:48:36 +020034 printk(BIOS_DEBUG, "i82801gx_ide: initializing...");
Stefan Reinauera8e11682009-03-11 14:54:18 +000035 if (config == NULL) {
Uwe Hermann607614d2010-11-18 20:12:13 +000036 printk(BIOS_ERR, "\ni82801gx_ide: Not mentioned in devicetree.cb!\n");
Stefan Reinaueraca6ec62009-10-26 17:12:21 +000037 // Trying to set somewhat safe defaults instead of bailing out.
Stefan Reinauera8e11682009-03-11 14:54:18 +000038 enable_primary = enable_secondary = 1;
39 } else {
40 enable_primary = config->ide_enable_primary;
41 enable_secondary = config->ide_enable_secondary;
42 }
Stefan Reinauerdebb11f2008-10-29 04:46:52 +000043
44 reg32 = pci_read_config32(dev, PCI_COMMAND);
45 pci_write_config32(dev, PCI_COMMAND, reg32 | PCI_COMMAND_IO | PCI_COMMAND_MASTER);
46
47 /* Native Capable, but not enabled. */
48 pci_write_config8(dev, 0x09, 0x8a);
49
50 ideTimingConfig = pci_read_config16(dev, IDE_TIM_PRI);
51 ideTimingConfig &= ~IDE_DECODE_ENABLE;
52 ideTimingConfig |= IDE_SITRE;
53 if (enable_primary) {
54 /* Enable primary IDE interface. */
55 ideTimingConfig |= IDE_DECODE_ENABLE;
56 ideTimingConfig |= (2 << 12); // ISP = 3 clocks
57 ideTimingConfig |= (3 << 8); // RCT = 1 clock
58 ideTimingConfig |= (1 << 1); // IE0
59 ideTimingConfig |= (1 << 0); // TIME0
Paul Menzel7f1df8c2015-10-11 15:48:36 +020060 printk(BIOS_DEBUG, " IDE0");
Stefan Reinauerdebb11f2008-10-29 04:46:52 +000061 }
62 pci_write_config16(dev, IDE_TIM_PRI, ideTimingConfig);
63
64 ideTimingConfig = pci_read_config16(dev, IDE_TIM_SEC);
65 ideTimingConfig &= ~IDE_DECODE_ENABLE;
66 ideTimingConfig |= IDE_SITRE;
67 if (enable_secondary) {
68 /* Enable secondary IDE interface. */
69 ideTimingConfig |= IDE_DECODE_ENABLE;
70 ideTimingConfig |= (2 << 12); // ISP = 3 clocks
71 ideTimingConfig |= (3 << 8); // RCT = 1 clock
72 ideTimingConfig |= (1 << 1); // IE0
73 ideTimingConfig |= (1 << 0); // TIME0
Paul Menzel7f1df8c2015-10-11 15:48:36 +020074 printk(BIOS_DEBUG, " IDE1");
Stefan Reinauerdebb11f2008-10-29 04:46:52 +000075 }
76 pci_write_config16(dev, IDE_TIM_SEC, ideTimingConfig);
77
78 /* Set IDE I/O Configuration */
Stefan Reinaueraca6ec62009-10-26 17:12:21 +000079 reg32 = 0;
80 /* FIXME: only set FAST_* for ata/100, only ?CBx for ata/66 */
81 if (enable_primary)
82 reg32 |= SIG_MODE_PRI_NORMAL | FAST_PCB0 | PCB0 | FAST_PCB1 | PCB1;
Stefan Reinauerdebb11f2008-10-29 04:46:52 +000083 if (enable_secondary)
Stefan Reinaueraca6ec62009-10-26 17:12:21 +000084 reg32 |= SIG_MODE_SEC_NORMAL | FAST_SCB0 | SCB0 | FAST_SCB1 | SCB1;
Stefan Reinauerdebb11f2008-10-29 04:46:52 +000085 pci_write_config32(dev, IDE_CONFIG, reg32);
86
87 /* Set Interrupt Line */
88 /* Interrupt Pin is set by D31IP.PIP */
89 pci_write_config32(dev, INTR_LN, 0xff); /* Int 15 */
Stefan Reinauera8e11682009-03-11 14:54:18 +000090
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +000091 printk(BIOS_DEBUG, "\n");
Stefan Reinauerdebb11f2008-10-29 04:46:52 +000092}
93
Elyes HAOUAS99667032018-05-13 12:47:28 +020094static void ide_set_subsystem(struct device *dev, unsigned int vendor,
95 unsigned int device)
Stefan Reinauera8e11682009-03-11 14:54:18 +000096{
97 if (!vendor || !device) {
98 pci_write_config32(dev, PCI_SUBSYSTEM_VENDOR_ID,
99 pci_read_config32(dev, PCI_VENDOR_ID));
100 } else {
101 pci_write_config32(dev, PCI_SUBSYSTEM_VENDOR_ID,
102 ((device & 0xffff) << 16) | (vendor & 0xffff));
103 }
104}
105
106static struct pci_operations ide_pci_ops = {
107 .set_subsystem = ide_set_subsystem,
108};
109
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000110static struct device_operations ide_ops = {
111 .read_resources = pci_dev_read_resources,
112 .set_resources = pci_dev_set_resources,
113 .enable_resources = pci_dev_enable_resources,
114 .init = ide_init,
115 .scan_bus = 0,
116 .enable = i82801gx_enable,
Stefan Reinauera8e11682009-03-11 14:54:18 +0000117 .ops_pci = &ide_pci_ops,
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000118};
119
Uwe Hermannbddc6932008-10-29 13:51:31 +0000120/* 82801GB/GR/GDH/GBM/GHM/GU (ICH7/ICH7R/ICH7DH/ICH7-M/ICH7-M DH/ICH7-U) */
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000121static const struct pci_driver i82801gx_ide __pci_driver = {
122 .ops = &ide_ops,
123 .vendor = PCI_VENDOR_ID_INTEL,
Uwe Hermann5d7a1c82008-10-31 18:41:09 +0000124 .device = 0x27df,
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000125};