blob: 33f7ac75698a7de659a99934aad6b441829934b7 [file] [log] [blame]
Uwe Hermann1410c2d2007-05-29 10:37:52 +00001/*
Stefan Reinauer7e61e452008-01-18 10:35:56 +00002 * This file is part of the coreboot project.
Uwe Hermann1410c2d2007-05-29 10:37:52 +00003 *
4 * Copyright (C) 2007 Uwe Hermann <uwe@hermann-uwe.de>
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; either version 2 of the License, or
9 * (at your option) any later version.
10 *
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.
Uwe Hermann1410c2d2007-05-29 10:37:52 +000015 */
16
Uwe Hermann9da69f82007-11-30 02:08:26 +000017/* TODO: Check if this really works for all of the southbridges. */
18
19#include <stdint.h>
Uwe Hermann1410c2d2007-05-29 10:37:52 +000020#include <console/console.h>
21#include <device/device.h>
22#include <device/pci.h>
Kyösti Mälkkif1b58b72019-03-01 13:43:02 +020023#include <device/pci_ops.h>
Uwe Hermann1410c2d2007-05-29 10:37:52 +000024#include <device/pci_ids.h>
25#include "i82371eb.h"
26
27/**
28 * Initialize the IDE controller.
29 *
30 * Depending on the configuration variables 'ide0_enable' and 'ide1_enable'
Uwe Hermann9da69f82007-11-30 02:08:26 +000031 * enable or disable the primary and secondary IDE interface, respectively.
32 *
33 * Depending on the configuration variable 'ide_legacy_enable' enable or
34 * disable access to the legacy IDE ports and the PCI Bus Master IDE I/O
35 * registers (this is required for e.g. FILO).
Uwe Hermann1410c2d2007-05-29 10:37:52 +000036 *
37 * @param dev The device to use.
38 */
Uwe Hermann9da69f82007-11-30 02:08:26 +000039static void ide_init_enable(struct device *dev)
Uwe Hermann1410c2d2007-05-29 10:37:52 +000040{
Uwe Hermann9da69f82007-11-30 02:08:26 +000041 u16 reg16;
Uwe Hermann56a91252007-06-03 16:57:27 +000042 struct southbridge_intel_i82371eb_config *conf = dev->chip_info;
Uwe Hermann1410c2d2007-05-29 10:37:52 +000043
44 /* Enable/disable the primary IDE interface. */
Uwe Hermann9da69f82007-11-30 02:08:26 +000045 reg16 = pci_read_config16(dev, IDETIM_PRI);
46 reg16 = ONOFF(conf->ide0_enable, reg16, IDE_DECODE_ENABLE);
47 pci_write_config16(dev, IDETIM_PRI, reg16);
Sylvain Hitier5b2fd1ea2010-10-11 23:22:24 +000048 printk(BIOS_DEBUG, "IDE: %s IDE interface: %s\n", "Primary",
Uwe Hermann9da69f82007-11-30 02:08:26 +000049 conf->ide0_enable ? "on" : "off");
Uwe Hermann1410c2d2007-05-29 10:37:52 +000050
51 /* Enable/disable the secondary IDE interface. */
Uwe Hermann9da69f82007-11-30 02:08:26 +000052 reg16 = pci_read_config16(dev, IDETIM_SEC);
53 reg16 = ONOFF(conf->ide1_enable, reg16, IDE_DECODE_ENABLE);
54 pci_write_config16(dev, IDETIM_SEC, reg16);
Sylvain Hitier5b2fd1ea2010-10-11 23:22:24 +000055 printk(BIOS_DEBUG, "IDE: %s IDE interface: %s\n", "Secondary",
Uwe Hermann9da69f82007-11-30 02:08:26 +000056 conf->ide1_enable ? "on" : "off");
57
58 /* Enable access to the legacy IDE ports (both primary and secondary),
59 * and the PCI Bus Master IDE I/O registers.
60 * Only do this if at least one IDE interface is enabled.
61 */
62 if (conf->ide0_enable || conf->ide1_enable) {
63 reg16 = pci_read_config16(dev, PCI_COMMAND);
64 reg16 = ONOFF(conf->ide_legacy_enable, reg16,
65 (PCI_COMMAND_IO | PCI_COMMAND_MASTER));
66 pci_write_config16(dev, PCI_COMMAND, reg16);
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +000067 printk(BIOS_DEBUG, "IDE: Access to legacy IDE ports: %s\n",
Uwe Hermann9da69f82007-11-30 02:08:26 +000068 conf->ide_legacy_enable ? "on" : "off");
Uwe Hermann1410c2d2007-05-29 10:37:52 +000069 }
Uwe Hermann1410c2d2007-05-29 10:37:52 +000070}
71
Uwe Hermann9da69f82007-11-30 02:08:26 +000072/**
73 * Initialize the Ultra DMA/33 support of the IDE controller.
74 *
75 * Depending on the configuration variables 'ide0_drive0_udma33_enable',
76 * 'ide0_drive1_udma33_enable', 'ide1_drive0_udma33_enable', and
77 * 'ide1_drive1_udma33_enable' enable or disable Ultra DMA/33 support for
78 * the respective IDE controller and drive.
79 *
80 * Only do that if the respective controller is actually enabled, of course.
81 *
82 * @param dev The device to use.
83 */
84static void ide_init_udma33(struct device *dev)
85{
86 u8 reg8;
87 struct southbridge_intel_i82371eb_config *conf = dev->chip_info;
88
89 /* Enable/disable UDMA/33 operation (primary IDE interface). */
90 if (conf->ide0_enable) {
91 reg8 = pci_read_config8(dev, UDMACTL);
92 reg8 = ONOFF(conf->ide0_drive0_udma33_enable, reg8, PSDE0);
93 reg8 = ONOFF(conf->ide0_drive1_udma33_enable, reg8, PSDE1);
94 pci_write_config8(dev, UDMACTL, reg8);
95
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +000096 printk(BIOS_DEBUG, "IDE: %s, drive %d: UDMA/33: %s\n",
Uwe Hermann9da69f82007-11-30 02:08:26 +000097 "Primary IDE interface", 0,
98 conf->ide0_drive0_udma33_enable ? "on" : "off");
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +000099 printk(BIOS_DEBUG, "IDE: %s, drive %d: UDMA/33: %s\n",
Uwe Hermann9da69f82007-11-30 02:08:26 +0000100 "Primary IDE interface", 1,
101 conf->ide0_drive1_udma33_enable ? "on" : "off");
102 }
103
104 /* Enable/disable Ultra DMA/33 operation (secondary IDE interface). */
105 if (conf->ide1_enable) {
106 reg8 = pci_read_config8(dev, UDMACTL);
107 reg8 = ONOFF(conf->ide1_drive0_udma33_enable, reg8, SSDE0);
108 reg8 = ONOFF(conf->ide1_drive1_udma33_enable, reg8, SSDE1);
109 pci_write_config8(dev, UDMACTL, reg8);
110
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000111 printk(BIOS_DEBUG, "IDE: %s, drive %d: UDMA/33: %s\n",
Uwe Hermann9da69f82007-11-30 02:08:26 +0000112 "Secondary IDE interface", 0,
113 conf->ide1_drive0_udma33_enable ? "on" : "off");
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000114 printk(BIOS_DEBUG, "IDE: %s, drive %d: UDMA/33: %s\n",
Uwe Hermann9da69f82007-11-30 02:08:26 +0000115 "Secondary IDE interface", 1,
116 conf->ide1_drive1_udma33_enable ? "on" : "off");
117 }
118}
119
120/**
121 * IDE init for the Intel 82371FB/SB IDE controller.
122 *
123 * These devices do not support UDMA/33, so don't attempt to enable it.
124 *
125 * @param dev The device to use.
126 */
127static void ide_init_i82371fb_sb(struct device *dev)
128{
129 ide_init_enable(dev);
130}
131
132/**
133 * IDE init for the Intel 82371AB/EB/MB IDE controller.
134 *
135 * @param dev The device to use.
136 */
137static void ide_init_i82371ab_eb_mb(struct device *dev)
138{
139 ide_init_enable(dev);
140 ide_init_udma33(dev);
141}
142
143/* Intel 82371FB/SB */
Uwe Hermann312673c2009-10-27 21:49:33 +0000144static const struct device_operations ide_ops_fb_sb = {
Uwe Hermann1410c2d2007-05-29 10:37:52 +0000145 .read_resources = pci_dev_read_resources,
146 .set_resources = pci_dev_set_resources,
147 .enable_resources = pci_dev_enable_resources,
Uwe Hermann9da69f82007-11-30 02:08:26 +0000148 .init = ide_init_i82371fb_sb,
Uwe Hermann1410c2d2007-05-29 10:37:52 +0000149 .scan_bus = 0,
Uwe Hermann9da69f82007-11-30 02:08:26 +0000150 .enable = 0,
151 .ops_pci = 0, /* No subsystem IDs on 82371XX! */
Uwe Hermann1410c2d2007-05-29 10:37:52 +0000152};
153
Uwe Hermann9da69f82007-11-30 02:08:26 +0000154/* Intel 82371AB/EB/MB */
Uwe Hermann312673c2009-10-27 21:49:33 +0000155static const struct device_operations ide_ops_ab_eb_mb = {
Uwe Hermann9da69f82007-11-30 02:08:26 +0000156 .read_resources = pci_dev_read_resources,
157 .set_resources = pci_dev_set_resources,
158 .enable_resources = pci_dev_enable_resources,
159 .init = ide_init_i82371ab_eb_mb,
160 .scan_bus = 0,
161 .enable = 0,
162 .ops_pci = 0, /* No subsystem IDs on 82371XX! */
163};
164
165/* Intel 82371FB (PIIX) */
166static const struct pci_driver ide_driver_fb __pci_driver = {
167 .ops = &ide_ops_fb_sb,
168 .vendor = PCI_VENDOR_ID_INTEL,
169 .device = PCI_DEVICE_ID_INTEL_82371FB_IDE,
170};
171
172/* Intel 82371SB (PIIX3) */
173static const struct pci_driver ide_driver_sb __pci_driver = {
174 .ops = &ide_ops_fb_sb,
175 .vendor = PCI_VENDOR_ID_INTEL,
176 .device = PCI_DEVICE_ID_INTEL_82371SB_IDE,
177};
178
179/* Intel 82371MX (MPIIX) */
180static const struct pci_driver ide_driver_mx __pci_driver = {
181 .ops = &ide_ops_fb_sb,
182 .vendor = PCI_VENDOR_ID_INTEL,
183 .device = PCI_DEVICE_ID_INTEL_82371MX_ISA_IDE,
184};
185
186/* Intel 82437MX (part of the 430MX chipset) */
187static const struct pci_driver ide_driver_82437mx __pci_driver = {
188 .ops = &ide_ops_fb_sb,
189 .vendor = PCI_VENDOR_ID_INTEL,
190 .device = PCI_DEVICE_ID_INTEL_82437MX_ISA_IDE,
191};
192
193/* Intel 82371AB/EB/MB */
194static const struct pci_driver ide_driver_ab_eb_mb __pci_driver = {
195 .ops = &ide_ops_ab_eb_mb,
Uwe Hermann1410c2d2007-05-29 10:37:52 +0000196 .vendor = PCI_VENDOR_ID_INTEL,
197 .device = PCI_DEVICE_ID_INTEL_82371AB_IDE,
198};